-1

I don't know enough about php to understand how to fix this. I've tried for the entire day and still can't fix it. I'm assuming this is an easy fix for those knowledgeable about php. I've read the other responses to similar questions, I've tried php.net (which doesn't mention $dom) but the code seems to be so different as to make it too difficult to connect the dots for someone as new at php as me.

Error message:

Warning: array_push() expects parameter 1 to be array, null given in 

Line of code it is referring to:

array_push($dom[($dom[$key]['parent'])]['trids'], $key);

Same error, separate line of code:

$cellid = array_push($dom[$trid]['cellpos'], array('startx' => $this->x));

Please help! Thanks in advance!

Aniket
  • 9,622
  • 5
  • 40
  • 62
user3993907
  • 11
  • 1
  • 1
  • 4
    _“I've tried php.net (which doesn't mention $dom)”_ – well, that’s because that is just a variable name – would be a bit excessive if the manual was to mention every possible variable name conceivable, don’t you think? – CBroe Aug 31 '14 at 03:17
  • The code can be trivially reproduces ad so: `$noarray = null; array_push($noarray, "foo")`. So then, why is the "array" supplied as an argument *really* null? Well, that's just troubleshooting.. – user2864740 Aug 31 '14 at 03:54

2 Answers2

1

You have to create the array before you can array_push onto it. Apparently, you haven't created an array in $dom[($dom[$key]['parent'])]['trids'] yet.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
1

I had a similar error and i managed to solve it by cleaning up my HTML. In my case there were missing "concatenators" (.) on the tr rows. Check row 2 in the example below, there is no dot (.) before the equal sign that can result in such an error.

$tbl = '<table border="0" cellpadding="5">';
$tbl = '<tr style="text-align:justify;">'."\n";
$tbl .= '<td style="width: 100%;"></td>'."\n";
$tbl .= '</tr>';    
$tbl .= '</table>'."\n";

The correct version will be

$tbl = '<table border="0" cellpadding="5">';
$tbl .= '<tr style="text-align:justify;">'."\n";
$tbl .= '<td style="width: 100%;"></td>'."\n";
$tbl .= '</tr>';    
$tbl .= '</table>'."\n";

Also ensure that when you are trying to format your tables and create separate rows outside the main table these rows must not be stand alones but should be inside tags and then you use then as sub-tables inside the main table.

Wrong version:

$subtbl = '<tr style="text-align:justify;">'."\n";
$subtbl .= '<td style="width: 100%;>Scores 1</td>'."\n";
$subtbl .= '<td style="width: 100%;>Scores 2</td>'."\n";
$subtbl .= '</tr>';

$maintbl = '<table border="0" cellpadding="5">';
$maintbl .= '<tr style="text-align:justify;">'."\n";
$maintbl .= '<td style="width: 100%;>'.$tbl.'</td>'."\n";
$maintbl .= '</tr>';
$maintbl .= '</table>';

Correct version:

$subtbl = '<table border="0" cellpadding="5">';
$subtbl .= '<tr style="text-align:justify;">'."\n";
$subtbl .= '<td style="width: 50%;>Scores 1</td>'."\n";
$subtbl .= '<td style="width: 50%;>Scores 2</td>'."\n";
$subtbl .= '</tr>';
$subtbl .= '</table>';

$maintbl = '<table border="0" cellpadding="5">';
$maintbl .= '<tr style="text-align:justify;">'."\n";
$maintbl .= '<td style="width: 100%;>'.$tbl.'</td>'."\n";
$maintbl .= '</tr>';
$maintbl .= '</table>'
B.K
  • 847
  • 10
  • 6