PHP - Remove subsequent array values if key found -


$week_link_arr

array (     [0] => 1-4_1*oct-2015     [1] => 5-11_2*oct-2015     [2] => 12-18_3*oct-2015     [3] => 19-25_4*oct-2015     [4] => 26-31_5*oct-2015 ) 

$current_week_url

1-4_1*oct-2015 

tried using array_search key , remove unset if found:

if (($key = array_search($current_week_url, $week_link_arr)) !== false) {     unset($week_link_arr[$key]);     } 

output

array (     [1] => 5-11_2*oct-2015     [2] => 12-18_3*oct-2015     [3] => 19-25_4*oct-2015     [4] => 26-31_5*oct-2015 ) 

this removes key found. instead if key found need remove subsequent array elements. exepected output key 1-4_1*oct-2015

array (     [0] => 1-4_1*oct-2015 ) 

if key 5-11_2*oct-2015,

array (     [0] => 1-4_1*oct-2015     [1] => 5-11_2*oct-2015 ) 

do mean this?

if (($key = array_search($current_week_url, $week_link_arr)) !== false) {       $week_link_arr = array_slice($week_link_arr, 0, $key + 1); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -