sorry couldn't frame a better title.
So here's the problem
i have a function inside functions.php
function show_news(){
$id_counter = 1;
$json_news = array(
"id" => 0,
"title" => ""
);
$json_o = json_decode(file_get_contents(JSON_DATA_FOLDER.'news.json'));
foreach ($json_o as $id => $news_category)
{
echo '<h2>'.$id.'<h2>';
foreach ($news_category as $news)
{
if(IsNullOrEmptyString($news->id)){$json_news['id'] = $id_counter; $id_counter++;}
else{$json_news['id']=$news->id;}
if(!IsNullOrEmptyString($news->title)){$json_news['title']=$news->title;}
var_dump($json_news);
echo "<br/>-------<br/>";
include('news-layout.php');
}
}
}
m reading a json file and for each element i am assigning its value to an array.
then i am including 'news-layout.php'. For testing purposes i've kept just these 3 lines of code inside 'news-layout.php'
<?php
global $json_news;
var_dump($json_news);
echo"<br/>=======================<hr/>";
?>
so i m doing a var_dump inside my function as well as on the included page. But i am getting strange result. Everything works fine except that var_dump($json_news) on included page shows NULL for first iteration of loop !!
here's the output
todays_specials
array(2) { ["id"]=> int(1) ["title"]=> string(26) "Okie Since I have to do it" }
-------
NULL
=======================
array(2) { ["id"]=> int(2) ["title"]=> string(16) "Vegetable Samosa" }
-------
array(2) { ["id"]=> int(2) ["title"]=> string(16) "Vegetable Samosa" }
=======================
array(2) { ["id"]=> int(3) ["title"]=> string(16) "Vegetable Pakora" }
-------
array(2) { ["id"]=> int(3) ["title"]=> string(16) "Vegetable Pakora" }
=======================
you can see that strange NULL coming there.
can anyone explain what's happening or how to fix it?