Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to unset the element from an array of objects
    text
    copied!<p>I have an array of operating systems ($os2) and i would like to remove all elements from array $phones , which dont have one of these operating systems. So i did this, but for some reason it's not working...</p> <pre><code>$os2 = array("BlackBerry", "Android"); if(count($os2)!=0) { for($i = 0; $i&lt;count($phones); $i++) { if(!in_array($phones[$i]-&gt;os, $os2)) { unset($phones[$i]); } } } </code></pre> <p>This is one element from the phones array:</p> <pre><code>[0] =&gt; Equipment Object ( [carrierDescription:Equipment:private] =&gt; T-Mobile [carrierId:Equipment:private] =&gt; 59 [manufacturerID:Equipment:private] =&gt; 13 [manufacturerName:Equipment:private] =&gt; BlackBerry [manufacturerCode:Equipment:private] =&gt; Curve 9360 [productId:Equipment:private] =&gt; 60558 [currentEquipmentID:Equipment:private] =&gt; 29305 [equipmentName:Equipment:private] =&gt; BlackBerry Curve 9360 Black [equipmentType:Equipment:private] =&gt; Smartphone [equipmentShortDescription:Equipment:private] =&gt; [equipmentLongDescription:Equipment:private] =&gt; The BlackBerry Curve 9360 for T-Mobile is the next Curve in BlackBerry's line of smartphones. Running the latest BlackBerry 7 operating system and utilizing the powerful BlackBerry 7 Webkit-browser, the BlackBerry Curve 9360 provides an intuitive smartphone experience, perfect for those who depend on their smartphone to keep their personal and work lives organized. Encased in a sleek package, including a wide 2.4 inch screen, full QWERTY keyboard and navigation track-pad, the BlackBerry Curve 9360 is ideal for efficient mobile communication. This new smartphone is also equipped with essential smartphone features such as a 5 megapixel camera with flash, video recorder, and WiFi connectivity for voice and data for a premium smartphone experience, The new Curve 9360 delivers the world's best mobile communications and social experiences with the latest release of BlackBerry Messenger, or BBM. [sugRetailPrice:Equipment:private] =&gt; 400 [displayPrice:Equipment:private] =&gt; $999.99 [equipmentPrice:Equipment:private] =&gt; 0 [numericCost:Equipment:private] =&gt; 0 [rebateAmount:Equipment:private] =&gt; $0.00 [priceAfterRebate:Equipment:private] =&gt; Free [rebateDescription:Equipment:private] =&gt; Free Gift [equipmentImageFileSmall:Equipment:private] =&gt; images/phones/60558_s.jpg [equipmentImageFileMedium:Equipment:private] =&gt; images/phones/60558_m.jpg [equipmentImageFileLarge:Equipment:private] =&gt; images/phones/60558_l.jpg [manufacturerLogo:Equipment:private] =&gt; _images/logos/manufacturers/selected_manu_blackberry.gif [purchaseMode:Equipment:private] =&gt; Add a Line [productLink:Equipment:private] =&gt; r.aspx?p=BlackBerry%20Curve%209360%20Black&amp;c=T-Mobile&amp;r=wowphonefinder&amp;mode=1&amp;s=1 [upc:Equipment:private] =&gt; 610214626622 [compatibleAccessoriesPageURL:Equipment:private] =&gt; DeviceSpecificAccessories.aspx?referringdomain=wowphonefinder&amp;refcode1=standarddatafeed&amp;refcode2=&amp;productid=60558 [mods:Equipment:private] =&gt; [os:Equipment:private] =&gt; BlackBerry [tethering:Equipment:private] =&gt; [hotspot:Equipment:private] =&gt; [html:Equipment:private] =&gt; HTML [triG:Equipment:private] =&gt; 3G [fourG:Equipment:private] =&gt; [fiveMP:Equipment:private] =&gt; [bluetooth:Equipment:private] =&gt; bluetooth [camera:Equipment:private] =&gt; camera [mail:Equipment:private] =&gt; mail [gps:Equipment:private] =&gt; gps [international:Equipment:private] =&gt; international [mp3:Equipment:private] =&gt; MP3 [vcast:Equipment:private] =&gt; [wifi:Equipment:private] =&gt; wifi [tscreen:Equipment:private] =&gt; [appstore:Equipment:private] =&gt; appstore [fcamera:Equipment:private] =&gt; [ptt:Equipment:private] =&gt; [rugged:Equipment:private] =&gt; [sbluetooth:Equipment:private] =&gt; [qwerty:Equipment:private] =&gt; qwerty [nocolor:Equipment:private] =&gt; Curve 9360 [colors:Equipment:private] =&gt; Black Black [hasShort:Equipment:private] =&gt; [hasReview:Equipment:private] =&gt; [hasAlternative:Equipment:private] =&gt; [hasAlternativeExpert:Equipment:private] =&gt; [order:Equipment:private] =&gt; [review:Equipment:private] =&gt; [id] =&gt; 260 ) </code></pre> <p>Btw...its working this way, but i will be really happy if someone have the solution without using the another variable, just with unset method...</p> <pre><code>if(count($os2)!=0) { $ph = array(); foreach($phones as $phone) { foreach($os2 as $o) { if($phone-&gt;os == $o) {array_push($ph,$phone);} } } $phones = $ph; } </code></pre> <p>Does anybody see what am I doing wrong? :) Thanks for your answers...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload