访问Json_encoded数组中的Matrix数组值

I have a php array that I assigned to a javascript variable with json_encode. The php array is numerical not associative.

Example: simpleArray[5][7]=1.50. I need to be able to access the 1.50 after the array has been json_encoded based on the index values.

PHP:

$simpleArray= [];   

foreach($childProducts as $child) { //cycle through simple products to find applicable
    $simpleArray[$child->getVendor()][$child->getColor()] = $child->getPrice();
    var_dump ($simpleArray);
}

Javascript:

var simpleArray = <?=json_encode($simpleArray)?>;
//..lots of unrelated code
for(var i=0; i < IDs.length; i++)
{   
    console.log(simpleArray);//see the picture of me below
    var colorSelected = $j("#attribute92 option:selected").val(); //integer value

    $j('.details'+data[i].vendor_id).append('<li class="priceBlock">$'+simpleArray[i][colorSelected]+'</li>');
}

Console.log(simpleArray):

enter image description here

查看全部
doushua7737
doushua7737
2013/05/23 20:18
  • php
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复