-1

I'm trying to search a array and navigate to the next and previous values

$ids = $res->result_array();

returns

array(3) {
  [0]=>
  array(1) {
    ["qid"]=>
    string(5) "63697"
  }
  [1]=>
  array(1) {
    ["qid"]=>
    string(5) "63706"
  }
  [2]=>
  array(1) {
    ["qid"]=>
    string(5) "63709"
  }
}

but when i try to search for the index it returns false

$curr_index = array_search($this->uri->segment(4), $q);

returns

bool(false) 

$this->uri->segment(4) is the qid.

I want to navigate with the array by increasing and decreasing by one so I can get the next and previous values.

Can someone please tell what am I doing wrong here?

2
  • your array is multidimensional. array_search will search the first level only and that consists of array, array, array. Also, please point out why none of stackoverflow.com/search?q=search+multidimensional+array+php answered your question. Commented Dec 5, 2011 at 7:53
  • @Gordon i didnt notice the second one and most of the replies i saw didnt have the array_search(). Thanks for the help. :) Commented Dec 5, 2011 at 8:07

1 Answer 1

2

You have an array of arrays, you could search it like this:

$curr_index = array_search(array('qid' => $this->uri->segment(4)), $q);

Where you are actually searching for an array instead of a string.

Working example: http://codepad.viper-7.com/Ff0sAq

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.