Thursday, July 8, 2021

In a array how to empty value place in last position and make a new array.

 

Code:-


$a = array("1"=>"test1", "2"=>"test2", "3"=>"", "4" => "test4");

echo "<pre>Original array get<br><br><br><br><br>";
print_r($a);

$t1 = array();
$t2 = array();
foreach ($a as $key => $value) {
if($value != '') {
$t1[] = $value;
}else {
$t2[] = $value;
}
}
 $t = array_merge($t1, $t2);

 echo "<br><br><pre>Make a new array <br><br><br>"; print_r($t); exit;

Output:-




No comments:

Post a Comment

If you have any problem please let me know.