I am attempting to use a foreach to output the array below. I have created this array via array_push() based on preg_match if/else.
Array (
[0] => Array (
[date] =>
[clickurl] => some data
[url] => some data
[dispurl] => some Data...
[title] => Transformers: Revenge of the Fallen : Reviews
[abstract] => "Transformers: Revenge of the Fallen" is a horrible experience of unbearable length, briefly punctuated by three or four amusing moments.
)
[1] => Array (
[date] =>
[clickurl] => some data
[url] => some data
[dispurl] => some Data...
[title] => Transformers : Reviews
[abstract] => After a string of bad-to-mediocre films, director Michael Bay scores with blockbuster battling robots in "Transformers."
)
)
When attempting to output the array:
foreach ($reviewArr as $review) {
echo($review['clickurl']. '<br/><br/>');
}
The output is “A” which is the first letter of Array at the start of the array above. This is the same result as using $review[0];
When using:
foreach ($reviewArr as $review) {
echo($review. '<br/><br/>');
}
the output is:
Array (
[date] =>
[clickurl] => some data
[url] => some data
[dispurl] => some data...
[title] => Transformers : Reviews
[abstract] => After a string of bad-to-mediocre films, director Michael Bay scores with blockbuster battling robots in "Transformers."
)
I am not sure why this is happening. Any help will be greatly appreciated.
thanks!
UPDATE =
This is the original Array that I parse below to split into two different arrays.
Array
(
[bossresponse] => Array
(
[responsecode] => 200
[web] => Array
(
[start] => 0
[count] => 14
[totalresults] => 14
[results] => Array
(
[0] => Array
(
[date] =>
[clickurl] => http://url.com/1
[url] => http://url.com/1
[dispurl] => http://url.com/1...
[title] => Title of Content 1
[abstract] => This is the summary, This is the summary, This is the summary, ...
)
[1] => Array
(
[date] =>
[clickurl] => http://url.com/2
[url] => http://url.com/2
[dispurl] => http://url.com/2...
[title] => Title of Content 2
[abstract] => This is the summary, This is the summary, This is the summary, ...
)
)
)
)
)
This is how I am setting the $reviewArr[].
foreach ($results['bossresponse']['web']['results'] as $key => $result) {
$url = $result['clickurl'];
$title = $result['title'];
$abstract = $result['abstract'];
$resultItem = print_r($results['bossresponse']['web']['results'][$key], true);
if (preg_match ("/reviews/i", "$url")) {
array_push($reviewArr, "$resultItem");
} else {
array_push($resultsArr, "$resultItem");
}
}
UPDATE #2 –
I see thanks to @fabio that I am simply setting a string with $resultItem above. How can I achieve creating a multidimensional array? How can I build this as an array – all of my attempts returned errors, or a string.
Array
(
[0] => Array
(
[date] =>
[clickurl] => http://url.com/1
[url] => http://url.com/1
[dispurl] => http://url.com/1...
[title] => Title of Content 1
[abstract] => This is the summary, This is the summary, This is the summary, ...
)
[1] => Array
(
[date] =>
[clickurl] => http://url.com/2
[url] => http://url.com/2
[dispurl] => http://url.com/2...
[title] => Title of Content 2
[abstract] => This is the summary, This is the summary, This is the summary, ...
)
)
Change:
to: