Reputation:
I've a week off work so I'm keeping busy trying to learn php.
I want to check the contents of my array by printing out whats contrained in them.
foreach ($articleList as $item)
{
$this->articles[] = array(
'url' => $this->domain . $item->getElementsByTagName('a')->item(0)->getAttribute('href'),
'title' => $item->getElementsByTagName('a')->item(0)->nodeValue,
// 'author' => $item->getElementsByTagName('em')->item(0)->getElementsByTagName('a')->item(0)->nodeValue,
'description' => $item->getElementsByTagName('div')->item(0)->nodeValue,
'article' => ''
);
}
foreach ($this->articles as $x)
{
echo $x;
}
The code at the bottom is where I am trying to print out each piece of the array and see what contents it holds, So i can understand what the code above it is doing.
But its just blank even though the array size is 30.
How can I go about doing this?
Many Thanks, -Code
Upvotes: 1
Views: 122
Reputation: 140903
foreach ($articleList as $item)
{
$this->articles[] = array(
'url' => $this->domain . $item->getElementsByTagName('a')->item(0)->getAttribute('href'),
'title' => $item->getElementsByTagName('a')->item(0)->nodeValue,
// 'author' => $item->getElementsByTagName('em')->item(0)->getElementsByTagName('a')->item(0)->nodeValue,
'description' => $item->getElementsByTagName('div')->item(0)->nodeValue,
'article' => ''
);
}
print_r($this->articles);
or
var_dump($this->articles)
Upvotes: 0
Reputation: 19635
Each item in your articles array is also an array, so you're likely seeing Array
when you echo out each one.
You will need to dive into each array in your articles array:
foreach ($this->articles as $x)
{
print_r($x);
}
Upvotes: 0
Reputation: 1357
In your foreach
loop, each element is itself an array.
Try print_r($x);
instead of echo $x;
Upvotes: 1