首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >存在Php键,但不可能访问给定的元素

存在Php键,但不可能访问给定的元素
EN

Stack Overflow用户
提问于 2018-12-20 05:40:13
回答 1查看 99关注 0票数 1

我在php中创建了这个数组;

代码语言:javascript
复制
array(21) { [0]=> array(3) { ["x"]=> int(0) ["y"]=> int(0) ["t"]=> string(3) "在" } [1]=> array(3) { ["x"]=> int(20) ["y"]=> int(0) ["t"]=> string(1) "P" } [2]=> array(3) { ["x"]=> int(40) ["y"]=> int(0) ["t"]=> string(3) "中" } [3]=> array(3) { ["x"]=> int(60) ["y"]=> int(0) ["t"]=> string(6) "使用" } [4]=> array(3) { ["x"]=> int(80) ["y"]=> int(0) ["t"]=> string(6) "类型" } [5]=> array(3) { ["x"]=> int(100) ["y"]=> int(0) ["t"]=> string(6) "工具" } [6]=> array(3) { ["x"]=> int(120) ["y"]=> int(0) ["t"]=> string(3) "时" } [7]=> array(3) { ["x"]=> int(140) ["y"]=> int(0) ["t"]=> string(3) "有" } [8]=> array(3) { ["x"]=> int(160) ["y"]=> int(0) ["t"]=> string(3) "几" } [9]=> array(3) { ["x"]=> int(180) ["y"]=> int(0) ["t"]=> string(3) "种" } [10]=> array(3) { ["x"]=> int(200) ["y"]=> int(0) ["t"]=> string(6) "方法" } [11]=> array(3) { ["x"]=> int(220) ["y"]=> int(0) ["t"]=> string(6) "可以" } [12]=> array(3) { ["x"]=> int(240) ["y"]=> int(0) ["t"]=> string(6) "确保" } [13]=> array(3) { ["x"]=> int(260) ["y"]=> int(0) ["t"]=> string(3) "您" } [14]=> array(3) { ["x"]=> int(280) ["y"]=> int(0) ["t"]=> string(6) "能够" } [15]=> array(3) { ["x"]=> int(300) ["y"]=> int(0) ["t"]=> string(3) "以" } [16]=> array(3) { ["x"]=> int(320) ["y"]=> int(0) ["t"]=> string(3) "所" } [17]=> array(3) { ["x"]=> int(340) ["y"]=> int(0) ["t"]=> string(3) "选" } [18]=> array(3) { ["x"]=> int(360) ["y"]=> int(0) ["t"]=> string(6) "格式" } [19]=> array(3) { ["x"]=> int(380) ["y"]=> int(0) ["t"]=> string(6) "对齐" } [20]=> array(3) { ["x"]=> int(400) ["y"]=> int(0) ["t"]=> string(6) "文本" } }

如您所见,它给出了一个22向量,每个元素都有x子数组。我查过钥匙了

代码语言:javascript
复制
array(21) { [0]=> int(0) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) [6]=> int(6) [7]=> int(7) [8]=> int(8) [9]=> int(9) [10]=> int(10) [11]=> int(11) [12]=> int(12) [13]=> int(13) [14]=> int(14) [15]=> int(15) [16]=> int(16) [17]=> int(17) [18]=> int(18) [19]=> int(19) [20]=> int(20) }

但是它无法对示例元素3进行资产配置;在这里给出偏移通知是代码

代码语言:javascript
复制
<?php 
$url = "https://pinyin-rest.pepebecker.com/hanzi/".urlencode("");
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL ,$url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close($curl);
//var_dump($data,$url);
$chars= json_decode($data);
$svgChinese = array();
$i = 0;
$cpt =0;
foreach ($chars as $one){
    if ( is_object($one)):
    $svgChinese[$cpt]["x"]= $i;
    $svgChinese[$cpt]["y"]= $y;
    $svgChinese[$cpt]["t"]= $one->simplified;
    $cpt++;
    $i+=20;
    endif;
}

var_dump($svgChinese);
var_dump(array_keys($svgChinese));
var_dump($svgChinese[3]); // error here

?>

您可以使用以下内容更改curl部件:这是在线文本:

代码语言:javascript
复制
$chars= json_decode('[[{"traditional":"哦","definitions":{"e2":{"pinyin":"é","translations":["to chant"],"zhuyin":"ㄜˊ"},"o2":{"pinyin":"ó","translations":["oh (interjection indicating doubt or surprise)"],"zhuyin":"ㄛˊ"},"o4":{"pinyin":"ò","translations":["oh (interjection indicating that one has just learned sth)"],"zhuyin":"ㄛ`"},"o5":{"pinyin":"o","translations":["sentence-final particle that conveys informality, warmth, friendliness or intimacy","may also indicate that one is stating a fact that the other person is not aware of"],"zhuyin":"ㄛ˙"}},"hsk":6,"simplified":"哦"}],[{"traditional":"哦","definitions":{"e2":{"pinyin":"é","translations":["to chant"],"zhuyin":"ㄜˊ"},"o2":{"pinyin":"ó","translations":["oh (interjection indicating doubt or surprise)"],"zhuyin":"ㄛˊ"},"o4":{"pinyin":"ò","translations":["oh (interjection indicating that one has just learned sth)"],"zhuyin":"ㄛ`"},"o5":{"pinyin":"o","translations":["sentence-final particle that conveys informality, warmth, friendliness or intimacy","may also indicate that one is stating a fact that the other person is not aware of"],"zhuyin":"ㄛ˙"}},"hsk":6,"simplified":"哦"}],[{"traditional":"哦","definitions":{"e2":{"pinyin":"é","translations":["to chant"],"zhuyin":"ㄜˊ"},"o2":{"pinyin":"ó","translations":["oh (interjection indicating doubt or surprise)"],"zhuyin":"ㄛˊ"},"o4":{"pinyin":"ò","translations":["oh (interjection indicating that one has just learned sth)"],"zhuyin":"ㄛ`"},"o5":{"pinyin":"o","translations":["sentence-final particle that conveys informality, warmth, friendliness or intimacy","may also indicate that one is stating a fact that the other person is not aware of"],"zhuyin":"ㄛ˙"}},"hsk":6,"simplified":"哦"}],[{"traditional":"哦","definitions":{"e2":{"pinyin":"é","translations":["to chant"],"zhuyin":"ㄜˊ"},"o2":{"pinyin":"ó","translations":["oh (interjection indicating doubt or surprise)"],"zhuyin":"ㄛˊ"},"o4":{"pinyin":"ò","translations":["oh (interjection indicating that one has just learned sth)"],"zhuyin":"ㄛ`"},"o5":{"pinyin":"o","translations":["sentence-final particle that conveys informality, warmth, friendliness or intimacy","may also indicate that one is stating a fact that the other person is not aware of"],"zhuyin":"ㄛ˙"}},"hsk":6,"simplified":"哦"}],[{"traditional":"哦","definitions":{"e2":{"pinyin":"é","translations":["to chant"],"zhuyin":"ㄜˊ"},"o2":{"pinyin":"ó","translations":["oh (interjection indicating doubt or surprise)"],"zhuyin":"ㄛˊ"},"o4":{"pinyin":"ò","translations":["oh (interjection indicating that one has just learned sth)"],"zhuyin":"ㄛ`"},"o5":{"pinyin":"o","translations":["sentence-final particle that conveys informality, warmth, friendliness or intimacy","may also indicate that one is stating a fact that the other person is not aware of"],"zhuyin":"ㄛ˙"}},"hsk":6,"simplified":"哦"}],[{"traditional":"哦","definitions":{"e2":{"pinyin":"é","translations":["to chant"],"zhuyin":"ㄜˊ"},"o2":{"pinyin":"ó","translations":["oh (interjection indicating doubt or surprise)"],"zhuyin":"ㄛˊ"},"o4":{"pinyin":"ò","translations":["oh (interjection indicating that one has just learned sth)"],"zhuyin":"ㄛ`"},"o5":{"pinyin":"o","translations":["sentence-final particle that conveys informality, warmth, friendliness or intimacy","may also indicate that one is stating a fact that the other person is not aware of"],"zhuyin":"ㄛ˙"}},"hsk":6,"simplified":"哦"}]]');
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-20 06:30:12

$svgEnglish没有索引3,因为$cpt从0开始,所以最后一个元素是$svgEnglish[2]

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53862976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档