Note that there are some explanatory texts on larger screens.

plurals
  1. POFind value and remove first level key from multi-dimensional array
    primarykey
    data
    text
    <p>This is my array.</p> <p>I am trying to locate a specific date and remove that entire key from the array (both corresponding start_time and end_time.</p> <pre><code> $c = array // Search all end_times $remove = '2012-06-24 17:00:59'; </code></pre> <blockquote> <p>array(2) {<br /></p> <blockquote> <p>[<strong>0</strong>]=><br /> array(2) {<br /></p> <blockquote> <p>[<strong>0</strong>]=><br />array(2) {<br /></p> <blockquote> <p>["ID"]=> string(2) "15"<br />["start_time"]=> string(19) "2012-06-24 08:00:00"<br /></p> </blockquote> <p>}<br /><br /> [<strong>1</strong>]=><br />array(2) {<br /></p> <blockquote> <p>["ID"]=> string(2) "15"<br />["end_time"]=> string(19) "2012-06-24 17:00:59"<br /></p> </blockquote> <p>}<br /></p> </blockquote> <p>}<br /></p> <p>[<strong>1</strong>]=><br /> array(2) {<br /></p> <blockquote> <p>[<strong>0</strong>]=><br /> array(2) {<br /></p> <blockquote> <p>["ID"]=> string(2) "28"<br />["start_time"]=> string(19) "2012-07-26 18:00:00"<br /></p> </blockquote> <p>}<br /></p> <p>[<strong>1</strong>]=><br /> array(2) {<br /></p> <blockquote> <p>["ID"]=> string(2) "28"<br />["end_time"]=> string(19) "2012-07-26 22:00:59"<br /></p> </blockquote> <p>}<br /></p> </blockquote> <p>}<br /></p> </blockquote> <p>}<br /></p> </blockquote> <p>This is the code I have so far. It works only when targeting the first start_time, or the second end_time, which suggests to me that the count is getting lost somewhere. I'm pretty new to PHP so I have very little clue as to whats next.</p> <pre><code> // recursive array search, look for value, remove key for ($i = 0, $count = count($c); $i &lt; $count; $i++) { if ($c[$i][$i]['end_time'] == $remove) { unset($c[$i]); } } </code></pre> <p>Would appreciate any help on this!<br /> Regards</p>
    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