How to parse inner array in JSON response with PHP?

PHP: Warning: array_push() expects parameter 1 to be array, boolean given?

  • I am reading 'PHP for absolute beginners' and I am stuck on page no. 183 , where it shows me an error--- Warning: array_push() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\simple_blog\inc\function… on line 60 Warning: array_pop() expects parameter 1 to be array, boolean given in C:\xampp\htdocs\simple_blog\index.php on line 27 and Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\simple_blog\index.php on line 68 I don't know why it is returning $e as a boolean , when it is an array! here is the code for "functions.inc.php" file--- <?php function retrieveEntries($db, $page, $url=NULL) { if(isset($url)) { $sql = "SELECT id, page, title, entry FROM entries WHERE url=? LIMIT 1"; $stmt = $db->prepare($sql); $stmt->execute(array($url)); $e = $stmt->fetch(); $fulldisp = 1; } else { $sql = "SELECT id, page, title, entry, url FROM entries WHERE page=? ORDER BY created DESC"; $stmt = $db->prepare($sql); $stmt->execute(array($page)); while($row = $stmt->fetch()) { $e[] = $row; $fulldisp = 0; } if(!is_array($e)) { $fulldisp = 1; $e = array( 'title' => 'No Entries Yet!', 'entry' => 'This Page Does Not Have An Entry Yet!!' ); } } array_push($e , $fulldisp ); return $e; } function sanitizeData($data) { if(!is_array($data)) { return strip_tags($data, "<a>"); } else { return array_map('sanitizeData', $data); } } function makeUrl($title) { $patterns = array( '/\s+/', '/(?!-)\W+/' ); $replacements = array('-' , ''); return preg_replace($patterns , $replacements , strtolower($title)); } ?> please help me out! thanks in advance!

  • Answer:

    Since I cant run it to duplicate/debug, I will suggest you look at this: When you set $e here, $e = $stmt->fetch(); what value does $e have?

Aman Grover at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.