我已经在php中创建了这个数组;
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 y t子数组。我检查了钥匙
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资产化;给予抵消通知 这是代码
<?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
部分:这是为了在线发送文本:
$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":"哦"}]]');
答案 0 :(得分:1)
$svgEnglish
没有索引3,因为$cpt
从0开始,所以最后一个元素为$svgEnglish[2]