Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to filter an array of object?
    primarykey
    data
    text
    <p>I've got an array of objects (show below) and I would like to write a function that returns the same array but with the "object(s)" that meet the criterion removed.</p> <p>The function would :</p> <p>1- check if the index exists 2- if it exists, checks for the required value and if the object's index is equal to that value, remove the whole object.</p> <p>For example :</p> <pre><code> Array ( [course] =&gt; Array ( [0] =&gt; stdClass Object ( [name] =&gt; Programmation Web [description] =&gt; [public] =&gt; 0 [requests] =&gt; 0 [id] =&gt; 245 [members] =&gt; Array ( [0] =&gt; stdClass Object ( [id] =&gt; 11 [name] =&gt; Robert Smith ) ) [projects] =&gt; Array ( [0] =&gt; stdClass Object ( [id] =&gt; 1923 [title] =&gt; Sans titre (1) [type] =&gt; portfolio ) ) [project_count] =&gt; 1 [admins] =&gt; Array ( [0] =&gt; stdClass Object ( [member] =&gt; 11 [firstname] =&gt; Robert [lastname] =&gt; Smith ) ) [topic_name] =&gt; Le PHP [activites] =&gt; Array ( [0] =&gt; stdClass Object ( [topic_name] =&gt; [topic_id] =&gt; 42 [post_parent] =&gt; 107 [post_body] =&gt; Oui moi aussi je me demande ça. [post_id] =&gt; 109 ) ) [forums] =&gt; Array ( [0] =&gt; stdClass Object ( [forum_name] =&gt; Discussion générale [forum_id] =&gt; 101 ) ) ) [1] =&gt; stdClass Object ( [name] =&gt; Les bases de données [description] =&gt; [public] =&gt; 0 [jointype] =&gt; controlled [grouptype] =&gt; course [membershiptype] =&gt; admin [topic_name] =&gt; Difficulté [activites] =&gt; Array ( [0] =&gt; stdClass Object ( [topic_name] =&gt; [topic_id] =&gt; 44 [post_parent] =&gt; 111 [post_body] =&gt; Ouah! [post_id] =&gt; 112 ) ) [forums] =&gt; Array ( [0] =&gt; stdClass Object ( [forum_name] =&gt; Le MySQL [forum_id] =&gt; 103 ) ) ) ) ) </code></pre> <p>If there's an object whose <strong>admins->member</strong> value is equal to 11, remove the object and return the array without this object. The returned array would thus be :</p> <pre><code> Array ( [course] =&gt; Array ( [0] =&gt; stdClass Object ( [name] =&gt; Programmation Web [description] =&gt; [public] =&gt; 0 [requests] =&gt; 0 [id] =&gt; 245 [members] =&gt; Array ( [0] =&gt; stdClass Object ( [id] =&gt; 11 [name] =&gt; Robert Smith (smithrobert) ) ) [projects] =&gt; Array ( [0] =&gt; stdClass Object ( [id] =&gt; 1923 [title] =&gt; Sans titre (1) [type] =&gt; portfolio ) ) [project_count] =&gt; 1 [admins] =&gt; Array ( [0] =&gt; stdClass Object ( [member] =&gt; 11 [firstname] =&gt; Robert [lastname] =&gt; Smith ) ) [topic_name] =&gt; Le PHP [activites] =&gt; Array ( [0] =&gt; stdClass Object ( [topic_name] =&gt; [topic_id] =&gt; 42 [post_parent] =&gt; 107 [post_body] =&gt; Oui moi aussi je me demande ça. [post_id] =&gt; 109 ) ) [forums] =&gt; Array ( [0] =&gt; stdClass Object ( [forum_name] =&gt; Discussion générale [forum_id] =&gt; 101 ) ) ) ) ) </code></pre> <p>How would I go about doing that?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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