Hi. I'm trying to dynamically allocate an array in php. Here is an example:
<?php
$name = 'Smith';
$harry = 'Harry';
$Margo = 'Margo';
$num1 = '1';
$num2 = '2';
$isLike[$name] = array($harry => $num2, $Margo => $num1);
//is basically the following and works…
//$isLike[''Smith'] = array('Harry' => 2, 'Margo' => 1);
//However I want to allocate the keys dynamically at page load through an array…
//So the following data could be represented dynamically..
$isLike['Brown'] = array('George' => 2, 'Barry' => 3, 'Sally' => 1);
$isLike['Harris'] = array('Millicent' => 2, 'Florence' => 3, 'Dorothy' => 1);
$isLike['Faversham'] = array('Hans' => 2, 'Wilhelm' => 3, 'Lisa' => 1);
//So I need something like this:
myArray = array();
myArray[0]='Brown';
myArray[1]='George';
myArray[2]='2';
myArray[3]='Barry';
myArray[4]='3';
myArray[5]='Sally';
myArray[6]='1';
//etc.
//Then I want to do something like this:
For($i = 0; $i < sizeof($myArray); $i++){
$isLike[$i]=array(isLike[$i+1] => $isLike[$i+2],$isLike[$i+3]=>$isLike[$i+4], $isLike[$i+5] =>$isLike[$i+6]);
}
//I need to use array keys as strings like above and don't want to use numbers to allocate array locations. Please someone help me before I go completely mad…
?>