I need helps on the PhP array method deployed below:
Actual PhP code:
$itemsB = array("Steve Jobs"=>"USA", "Thomas Edison"=>"USA");
echo $itemsB['Steve Jobs'];
echo '<br />';
echo $itemsB['Thomas Edison'];
Expected Result:
USA
USA
Created DIY method below base on the above and hope to retrieve the same result but failed (getting no output)? The reason I am using this DIY method due to I have a list of Profile Data that need to fill into the conventional array method of : $items = array(‘name1’=>’value1’, ‘name2’=>’value2’);
$ProfileName[0] = "\"Steve Jobs\"=>\"USA\"";
$ProfileName[1] = "\"Thomas Edison\"=>\"USA\"";
$items = array("$ProfileName[0]", "$ProfileName[1]");
echo $items['Steve Jobs'];
echo '<br />';
echo $items['Thomas Edison'];
Please advice!
Cheers
Alright, brief updates on what I am looking for if you still find unclear on the above. Below is the code to search Profile Name for autocomplete method on text field box. The code below is working if I entered the static values into the array. But, I have a list of Profile Names in the Database that I wanted to populate and add it into the array below. Thus, I thought of do some DIY that shown above. Unless there is other solution for this. Please advice
$q = strtolower($_GET["q"]);
if (!$q) return;
$items = array("Steve Jobs"=>"USA", "Thomas Edison"=>"USA");
foreach ($items as $key=>$value) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key|$value\n";
}//END IF
}//END FOR
This should work for you, if I’m understanding your question correctly:
This seems like a long way around to get to the same place, but you could try something like this.
Or something like this could help if you’re pulling stuff from the database: