I want to unset the value for certain condition . if i'm use unset keyword it through an error.please any one help me in this case.
$reportHeader = array("name" => !empty($name) ? "Name" : "0",
"number" => !empty($number) ? "Number" : "0");
In this case i print the Name and number is present if not present i return 0.but i no need to print 0.if condition fails i need to unset the value. I tried like this:
$reportHeader = array("name" => !empty($name) ? "Name" : unset(),
"number" => !empty($number) ? "Number" : unset();
But it through an error
You can't use
unset()like that, it expects a variable to be passed to it to unset (see the PHP documentation. Instead populate your array withnullvalues where the value hasn't been set and then usearray_filterto remove the indexes you don't want.