Reputation: 49
trying to pass string key and value into my array , here's the array
$array = array(
'id' =>1,
'name' => 'ahmed',
'age' => 16,
'country' => 'egypt',
$string,
);
and my string var is
$string = " 'city'=>'cairo' ";
when using the code in that way doesn't works so is there anyway to inserting string in a array as key and value
Upvotes: 0
Views: 100
Reputation: 791
Try this one
$array = array(
'id' =>1,
'name' => 'ahmed',
'age' => 16,
'country' => 'egypt',
);
$array['city'] = 'cairo';
print_r( $array);
it will output
Array ( [id] => 1 [name] => ahmed [age] => 16 [country] => egypt [city] => cairo )
Upvotes: 2