justinh Posted February 3, 2009 Share Posted February 3, 2009 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 />"; } ?> Quote Link to comment Share on other sites More sharing options...
Vebut Posted February 3, 2009 Share Posted February 3, 2009 http://php.net/unset Quote Link to comment Share on other sites More sharing options...
justinh Posted February 3, 2009 Author Share Posted February 3, 2009 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? Quote Link to comment Share on other sites More sharing options...
Vebut Posted February 3, 2009 Share Posted February 3, 2009 I don't get it, why use explode if you already have an array? Quote Link to comment Share on other sites More sharing options...
sasa Posted February 3, 2009 Share Posted February 3, 2009 <?php $pieces = explode("<br>", $bankinfo); foreach($pieces as $key => $value){ if($value == "" || $value == "UNIT QTY $ AMOUNT"){ unset($pieces[$key]); } echo $value . "<br />"; } ?> Quote Link to comment Share on other sites More sharing options...
printf Posted February 3, 2009 Share Posted February 3, 2009 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 ); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.