forum_amnesiac
05-15-2009, 12:14 PM
I'm trying to create an associative by reading from a table.
I can create the variable to make the array but for some reason it is not working, here is an example
$cat ='"8"=>"Antipasti", "17"=>"Capperi Medi", "1"=>"Carciofi", "2"=>"Cipolle", "3"=>"Funghi", "18"=>"Lupini", "4"=>"Melanzane", "16"=>"Olive Nere", "15"=>"Olive Verdi", "13"=>"Pate", "5"=>"Peperoni", "14"=>"Pesto", "6"=>"Pomodori", "12"=>"Sughi Biologici", "10"=>"Sughi Economici", "11"=>"Sughi Extra", "9"=>"Verdure", "7"=>"Zucchine"';
$cat1 = array($cat);
$cat2=array("8"=>"Antipasti", "17"=>"Capperi Medi", "1"=>"Carciofi", "2"=>"Cipolle", "3"=>"Funghi", "18"=>"Lupini", "4"=>"Melanzane", "16"=>"Olive Nere", "15"=>"Olive Verdi", "13"=>"Pate", "5"=>"Peperoni", "14"=>"Pesto", "6"=>"Pomodori", "12"=>"Sughi Biologici", "10"=>"Sughi Economici", "11"=>"Sughi Extra", "9"=>"Verdure", "7"=>"Zucchine",);
echo $cat1["2"];
echo $cat2["2"];
I have created variable $cat here with the contents hardcoded, normally this is created from the table.
However even in this example $cat1 returns nothing, $cat2 returns 'Cipolle' as I would expect.
Can somebody explain why it doesn't work as '$cat1 = array($cat);' and tell me how I should do it.
Thanks
I can create the variable to make the array but for some reason it is not working, here is an example
$cat ='"8"=>"Antipasti", "17"=>"Capperi Medi", "1"=>"Carciofi", "2"=>"Cipolle", "3"=>"Funghi", "18"=>"Lupini", "4"=>"Melanzane", "16"=>"Olive Nere", "15"=>"Olive Verdi", "13"=>"Pate", "5"=>"Peperoni", "14"=>"Pesto", "6"=>"Pomodori", "12"=>"Sughi Biologici", "10"=>"Sughi Economici", "11"=>"Sughi Extra", "9"=>"Verdure", "7"=>"Zucchine"';
$cat1 = array($cat);
$cat2=array("8"=>"Antipasti", "17"=>"Capperi Medi", "1"=>"Carciofi", "2"=>"Cipolle", "3"=>"Funghi", "18"=>"Lupini", "4"=>"Melanzane", "16"=>"Olive Nere", "15"=>"Olive Verdi", "13"=>"Pate", "5"=>"Peperoni", "14"=>"Pesto", "6"=>"Pomodori", "12"=>"Sughi Biologici", "10"=>"Sughi Economici", "11"=>"Sughi Extra", "9"=>"Verdure", "7"=>"Zucchine",);
echo $cat1["2"];
echo $cat2["2"];
I have created variable $cat here with the contents hardcoded, normally this is created from the table.
However even in this example $cat1 returns nothing, $cat2 returns 'Cipolle' as I would expect.
Can somebody explain why it doesn't work as '$cat1 = array($cat);' and tell me how I should do it.
Thanks