Jump to content

array_push


rashmi_k28

Recommended Posts

That won't work, since you're never setting $previous.

 

Try something like:

<?php
$test = explode(',','1,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1');
$prev = -1;
$new = array();
foreach ($test as $t) {
        if ($t != $prev) $new[] = $t;
        $prev = $t;
}
echo implode(',',$new);
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/110051-array_push/#findComment-564751
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.