I was wondering if theres a way to filter arrays in PHP via doing something like this:
if (!in_array("something",$something)
Now I'd like to get all the values that are NOT matched by the search criterion.
For instance if I have an array like this:
$options = array("Preview", "Live", "Completed");
and I pass the value for search: "Preview", I'd like to return these two elements in the array "Live" and "Completed" as a result of my array filtering...
Is there some way I could do this?
Edit:
We have an initial array like this:
$options = array("Preview", "Live", "Completed");
Initial input to the search of array is "Preview" string.
Output array that I'd like it to be is:
$newArray = array("Live", "Completed");
EDIT EDIT (WHAT IM ACTUALLY TRYING TO ACHIEVE):
Hi guys this is what I'm actually trying to do:
<?php foreach($active_brand as $brand?>
<select>
<?php if (in_array($brand['State'], $options)) { ?>
<option selected="selected" value="<?=$brand['id']?>"><?=$brand['State']?></option>
<?php }?>
<?php for($i=1;$i<count($options);$i++) { ?>
<option value="<?=$brand['id']?>"><?=array_diff($options, array($brand['State']))[$i]?></option>
<?php }?>
</select>
<?php }?>
As you can see guys, I have a column in my DB which is Called a "State"... It's basically a varchar where I keep my string stored... Brand state can only be the 3 following states:
Preview => Live => Completed
The first thing I do is set the current value to select list like following:
<?php if (in_array($brand['State'], $options)) { ?>
<option selected="selected" value="<?=$brand['id']?>"><?=$brand['State']?></option>
<?php }?>
Now I have defined an array like this in my phtml file like this:
$options = array("Preview", "Live", "Completed");
Now I'm simply trying to filter out the states that are not in the array and place them in my select tag like this:
<?php for($i=1;$i<count($options);$i++) { ?>
<option value="<?=$brand['id']?>"><?=array_diff($options, array($brand['State']))[$i]?></option>
<?php }?>
So that the structure in my select list is like following:
Current state of brand => defaultly selected => add the two missing states to select list (but not to add the current one that is set in DB)...
Can someone help me out?