Jump to content

Rearanging an array


cemeteryridge

Recommended Posts

That not how I need it to work. I need the empty values of index 1,2 to be erased and the value of 3 be relocated to 1;

like I explained in my first post;

$tank[0] = "User1";
$tank[1] = "";
$tank[2] = "";
$tank[3] = "User2";

to


$tank[0] = "User1";
$tank[1] = "User2";

 

Link to comment
https://forums.phpfreaks.com/topic/198567-rearanging-an-array/#findComment-1042108
Share on other sites

Sorry, didn't notice the arrangement of the keys in OP.

<?php
$tank[0] = "User1";
$tank[1] = "";
$tank[2] = "";
$tank[3] = "User2";

$tank = array_filter($tank);
sort($tank);
echo '<pre>'; print_r($tank); echo '</pre>';

?>

Maybe not with those values, but wouldn't sort have more of an effect than the OP would want?

Link to comment
https://forums.phpfreaks.com/topic/198567-rearanging-an-array/#findComment-1042124
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.