Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

using array_search() to find values in php

Im 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...