0

for example say i have an object array called $list looks like this:

<(stdClass)#16 (3) {
  ["1"]=>
  <(8) "50504496"
  ["2"]=>
  <(8) "12435374"
  ["3"]=>
  <(8) "12436374"

Im doing a foreach on the object array and removing them if they exist in the database i.e

   foreach($list as $l){

    //do the query

    if( it exists){
      //remove from objects: this is where i need help!!
      }
   }

i have the db logic, im just stuck to know how i can remove objects, i was thinking maybe i should create a new object and add them thier. thanks }

1

4 Answers 4

4

Use: unset

foreach($list as $key => $obj){
  if( exists .. ) {
      unset($list[$key]);
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanks brillant answer, what deos ... stand for is it 1,2 or 3 $var names
0

run your query and if it returns >0 number of rows then you have a result, use unset($object->$var) to unset a variable

Comments

0

Try like:

    foreach($list as $li)
    {
        if($li)
        {
            //copy into another array.
        }
    }

i thnk its may simple

1 Comment

how can i copy into another array?
0

Try like: $i=0;

  foreach($list as $li)
  {
      if($li)
      {
          $b[i] = $li;
          $i++;
      }
   }

array '$b' will hold the values in $list which are not null

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.