Fatal error: [] operator not supported for strings



PHP Snippet 1:

$foo = 'foo';
$foo[] = 'bar'; // ERROR!

PHP Snippet 2:

$name = $row['name'];
$date = $row['date'];
$text = $row['text'];
$date2 = $row['date2'];

PHP Snippet 3:

$name = 'String';

PHP Snippet 4:

$name[] = 'new value'; // fatal error

PHP Snippet 5:

$name = array();
$date = array();
$text = array();
$date2 = array();

PHP Snippet 6:

$foo='';
$foo[]='test';
print_r($foo);

PHP Snippet 7:

$users = array(); // not $users = ";
$users[] = "762";

PHP Snippet 8:

$a['index'] = [];
$a['index'][] = 'another value';
$a['index'][] = 'another value';
$a['index'][] = 'another value';
$a['index'][] = 'another value';

PHP Snippet 9:

if(is_array($variable_either_string_or_array)){
    // if it's an array, declaration is allowed:
    $variable_either_string_or_array[]=$additionalInfoData[$i];
}else{
    // if it's not an array, declaration it as follows:
    $variable_either_string_or_array=$additionalInfoData[$i];
}

PHP Snippet 10:

$name = array();
$name[] = $row['name'];

PHP Snippet 11:

$foo = array();
$foo[] = 'test'; // error    
$foo[] = "test"; // working fine

PHP Snippet 12:

$name=array();
$date=array();
$text=array();
$date2=array();
while ($row = mysql_fetch_array($nameresult1, MYSQL_ASSOC)) {
    $name[] = $row['name'];
    $date[] = $row['date'];
    $text[] = $row['text'];
    $date2[] = $row['date2 '];
}