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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -