The following code returns an associative array as follows
Array ( [1] => Array (
[url] => example.com
[title] => Title.example
[snippet] => snippet.example
) )
$blekkoArray = array();
foreach ($js->RESULT as $item)
{
$blekkoArray[$i]['url'] = str_replace ($find, '', ($item->{'Url'}) );
$blekkoArray[$i]['title'] = ($item->{'url_title'});
$blekkoArray[$i]['snippet'] = ($item->{'snippet'});
$i++;
}
print_r ($blekkoArray);
How can I modify the array so that instead of the array element been identified by 1,2,3
etc it would be identified by the url eg.
Array ( [example.com] => Array (
[title] => Title.example
[snippet] => snippet.example
) )
The other solutions seem to focus on changing the array after
foreach ($js->RESULT as $item)
{
$blekkoArray[str_replace ($find, '', ($item->{'Url'}))] = array(
'title'=> $item->{'url_title'},
'snip pet' => $item->{'snippet'}
);
}
That should make the array how you need it
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments