Jump to content

array delete?


justinh

Recommended Posts

i have this array

array(7) { [0]=>  string(20) "UNIT QTY $ AMOUNT" [1]=>  string(18) "1c 18 0.18+" [2]=>  string(18) "1c 18 0.18+" [3]=>  string(19) "TOTAL 0.36+" [4]=>  string(19) "TOTAL 0.00+" [5]=>  string(0) "" [6]=>  string(0) "" }

 

I looked all over PHP.net for a way to delete an element in an array, and can't seem to find it. Does anyone have an idea on how I would go about this?

 

This is what I have so far

 

 
<?php
$pieces  = explode("<br>", $bankinfo);
     foreach($pieces as $value){ 
       if($value == "" || $value == "UNIT QTY $ AMOUNT"){
         //toss it out
       }
       echo $value . "<br />";
     }   
?>
       

 

 

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/143606-array-delete/
Share on other sites

suwheet this worked

<?php 
$pieces  = explode("<br>", $bankinfo);
     foreach($pieces as $value){ 
       if($value == "" || $value == "UNIT QTY $ AMOUNT"){
            unset($value);
       }
       echo $value . "<br />";
     }   
?>

 

But... It's not unsetting the UNIT QTY & AMOUNT element, any idea why?

Link to comment
https://forums.phpfreaks.com/topic/143606-array-delete/#findComment-753466
Share on other sites

You can do something like this. Internally PHP is faster than any external loop with a single or more condition(s)!

 

<?php
$original = array ( 0 => 'UNIT QTY $ AMOUNT', 1 => 'junk', 2 => '' );

$original = array_diff ( $original, array ( '', 'UNIT QTY $ AMOUNT' ) );

print_r ( $original );

?>

Link to comment
https://forums.phpfreaks.com/topic/143606-array-delete/#findComment-753519
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.