Qu'est-ce que l'avis PHP et comment le reproduire:
Si vous envoyez un tableau PHP dans une fonction qui attend une chaîne comme: echoou print, alors l'interpréteur PHP convertira votre tableau en chaîne littérale Array, lèvera cet avis et continuez. Par exemple:
php> print(array(1,2,3))
PHP Notice: Array to string conversion in
/usr/local/lib/python2.7/dist-packages/phpsh/phpsh.php(591) :
eval()'d code on line 1
Array
Dans ce cas, la fonction printvide la chaîne littérale:Array vers stdout, puis enregistre l'avis dans stderr et continue.
Un autre exemple dans un script PHP:
<?php
$stuff = array(1,2,3);
print $stuff; //PHP Notice: Array to string conversion in yourfile on line 3
?>
Vous avez 2 options, soit convertir votre tableau PHP en String à l'aide d'un convertisseur tableau en chaîne, soit supprimer la notice PHP.
Correction 1: utilisez la fonction php intégrée print_r ou var_dump:
http://php.net/manual/en/function.print-r.php ou http://php.net/manual/en/function.var-dump.php
$stuff = array(1,2,3);
print_r($stuff);
$stuff = array(3,4,5);
var_dump($stuff);
Impressions:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
array(3) {
[0]=>
int(3)
[1]=>
int(4)
[2]=>
int(5)
}
Correction 2: utilisez json_encode pour réduire le tableau en chaîne json:
$stuff = array(1,2,3);
print json_encode($stuff); //Prints [1,2,3]
Correction 3: Rejoindre toutes les cellules du tableau ensemble:
<?php
$stuff = array(1,2,3);
print implode(", ", $stuff); //prints 1, 2, 3
print join(',', $stuff); //prints 1, 2, 3
?>
Correction 4: supprimer les avis:
error_reporting(0);
print(array(1,2,3)); //Prints 'Array' without a Notice.
$Texting[i]faute de frappe? Cela ne devrait-il pas être$Texting[$i]plutôt?