Ключ массива Php существует, но невозможно получить доступ к элементам

Я создал этот массив в 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":"哦"}]]');

1

Решение

$svgEnglish не имеет индекса 3 как $cpt начинается с 0, поэтому последний элемент будет $svgEnglish[2]

1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector