Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's quite a few problems in your code. Here's what you should do:</p> <ol> <li><code>explode</code> needs a delimiter. You want to separate it by commas, so do <code>explode(",","state/Gold,International/Participant,School/Participant,School/Bronze,national/Bronze,School/Gold")</code>.</li> <li>You should not use array_diff: in fact, the way you did it would remove just the elements that only contain 'Participant' - while they're more complex strings.</li> </ol> <p>What you need is a beautiful function called <code>array_filter</code>. It's one of the few really great things in PHP, so bear me for a little while I explain how it works.</p> <p>It takes two arguments: the array, and a function. </p> <p>It returns an array containing only the elements that, once passed to the function, will return true.</p> <p>Let's come back to your particular case. To check if a string contains a substring (that is, to check if in a given array element there is a 'Participant' string) you can use <code>strpos($haystack, $needle)</code>. It will return the position of your substr, or FALSE if it is not present.</p> <p>Another concept (solution is coming) we will use is pretty new in php, and is called "anonymous function". It's a function created on the fly, without a name, usually to be used as callback.</p> <p>Here is the code:</p> <pre><code> $string = "state/Gold,International/Participant,School/Participant,School/Bronze,national/Bronze,School/Gold"; $new_array = array_filter( explode(",",$string), //so, every element of this array gets checked against function ($var) { //this function here. if true is returned, it goes in $new_array return (strpos($haystack, 'Participant')=== NULL); } ); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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