i have array called $result, shown below:
array(1) { ["response"]=> array(3) { [0]=> array(1) { ["list"]=> array(2) { ["category"]=> string(6) "(noun)" ["synonyms"]=> string(27) "chelonian|chelonian reptile" } } [1]=> array(1) { ["list"]=> array(2) { ["category"]=> string(6) "(verb)" ["synonyms"]=> string(57) "capsize|turn turtle|overturn|turn over|tip over|tump over" } } [2]=> array(1) { ["list"]=> array(2) { ["category"]=> string(6) "(verb)" ["synonyms"]=> string(29) "hunt|run|hunt down|track down" } } } } i trying access ["synonyms"] element, , split each word , store in own string, or perhaps array of words. can see words separated | symbol.
i have tried following code, did not work (results did not display, explode did not work) :
$i=0; foreach ($result["response"] $value) { foreach ($value["list"]["synonyms"] $temp) { $alternative[$i] = explode ("|", $temp); $i++; } } //output results $j=0; foreach ($alternative $echoalternative) { echo $j.": ".$echoalternative; $j++; } any ideas? guys.
you're trying iterate on string in interior foreach. try
foreach ($result["response"] $value) { $alternative[$i] = explode ("|", $value["list"]["synonyms"]); $i++; }
Comments
Post a Comment