Hello I want create string to array. I have 4 variables:
<?php
$name = "John";
$address = "Moscow";
$born_date = "13-11-1995";
$color = "red";
$join = $name.":".$address.":".$born_date.":".$color;
$array = explode(':', $join);
print_r ($array);
?>
This array result is:
Array ( [0] => John [1] => Moscow [2] => 1995-11-13 [3] => red )
When I change $color variable to null like $color="";
This result like this:
Array ( [0] => John [1] => Moscow [2] => 1995-11-13 [3] => )
I want array number 3 not to show. I want if all $variable == NULL / $variable=="undefined" / $varable=""
Show like this:
Array ( [0] => John [1] => Moscow [2] => 1995-11-13)
The array shows only variable filled.
array_filter($array);or useifconditions. Or make your array usingifconditions and$array[] = $name;etc...not sure you need to create a string just toexplode()it to an array when you can just make an array.