0

Whats wrong in the array_values() function.

I tried assigning the $updated_f to array().

I get Warning: array_values() expects parameter 1 to be array, null given

$this_params = array_merge_recursive($params, array('f' => array($filter['prefix'] => array($item['id'])))); 

if (isset($this_params['f'])) {
    $updated_f = array(); 
   //Updated code
    if(isset($this_params['f']) && is_array($this_params['f']) && count($this_params['f']) >0)
    {
      foreach($this_params['f'] as $f_key => $assoc_array) {
         $updated_f[$f_key] = array_values($assoc_array);   //Warning here
       } 
    }
    $this_params['f'] = $updated_f;
  }
7
  • 1
    Pretty obvious isn't it? On at least one of the loops, $assoc_array is not an array, it is null. Print out $this_params['f'] and you'll see it... Commented Sep 15, 2016 at 5:58
  • check var_dump($this_params['f']); OR echo "<pre/>";print_r($this_params['f']); and check is it printing an array or not? to prevent yourself from error you need to add:- if (isset($this_params['f']) && is_array($this_params['f']) && count($this_params['f']) >0) { Commented Sep 15, 2016 at 6:00
  • Yes i printed out : echo '<pre>';print_r($this_params['f']); and i get : Array ( [r_103] => Array ( [0] => 62 ) ) Commented Sep 15, 2016 at 6:05
  • Please print out $assoc_array Commented Sep 15, 2016 at 6:10
  • I have added the condition @Anant, im still getting the same error Commented Sep 15, 2016 at 6:11

1 Answer 1

12

array_values() function accept only array type variable Below line

 $updated_f[$f_key] = array_values($assoc_array);   //Warning here

Replace line with

$updated_f[$f_key] = is_array($assoc_array)? array_values($assoc_array): array();   
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.