mardi 28 septembre 2021

Is it possible to use implode() as a condition ? If not, what's the best way to check if the array can be imploded?

I want implode an array in a loop. Sometime this array is a simple array so it works, sometime that's a multidimensional array and my script throw an error.

Is it possible to do something like that :

if (implode($array) ) {

$builded = implode($array);

}

I know that's possible with some function returning false like if (file_get_contents($file)). If not possible, what's the best way checking if an array can be imploded ?

I'm aware about if (count($array) == count($array, COUNT_RECURSIVE)) and others solutions checking if the array is multidimensional but that's not working with empty sub array (end i often got the case).

Aucun commentaire:

Enregistrer un commentaire