The Little Guy Posted May 9, 2011 Share Posted May 9, 2011 Maybe I am over thinking this, but I would like to see if their is another value after the current value without moving the internal array pointer. What can I do? Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/ Share on other sites More sharing options...
AbraCadaver Posted May 9, 2011 Share Posted May 9, 2011 That's very vague, maybe some code. But here is a vague answer: $i = 0; if(isset($array[i$+1])) { //something; } Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212880 Share on other sites More sharing options...
Psycho Posted May 9, 2011 Share Posted May 9, 2011 I think the OP is wanting to see if there are duplicate values in the array. So, if he is looping through the array and finds that element '2' has a value of 'foo', how would he determine if there is another value 'foo' in the array with a higher index. It would be helpful if you were to explain the process you are trying to accomplish. I can think of a few different solutions, but which one I would go with would be directly tied to what the goal is. But, most likely I would be using array_count_values(): http://php.net/manual/en/function.array-count-values.php Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212890 Share on other sites More sharing options...
Zurev Posted May 9, 2011 Share Posted May 9, 2011 I think the OP is wanting to see if there are duplicate values in the array. So, if he is looping through the array and finds that element '2' has a value of 'foo', how would he determine if there is another value 'foo' in the array with a higher index. It would be helpful if you were to explain the process you are trying to accomplish. I can think of a few different solutions, but which one I would go with would be directly tied to what the goal is. But, most likely I would be using array_count_values(): http://php.net/manual/en/function.array-count-values.php If it does involve removing duplicate values, array_unique is there and works wonders. Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212925 Share on other sites More sharing options...
The Little Guy Posted May 9, 2011 Author Share Posted May 9, 2011 basically I have an array, the array has sub arrays, and those sub arrays have a value called "processing" I want to loop through that array until all the "processing" values equal false. Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212944 Share on other sites More sharing options...
The Little Guy Posted May 9, 2011 Author Share Posted May 9, 2011 Basically Here is my array (this only has 2 values this can have lots of values): Array ( [0] => Array ( [thread] => Resource id #14 [processing] => 1 [thread_id] => 0 ) [1] => Array ( [thread] => Resource id #15 [processing] => 1 [thread_id] => 1 ) ) I want to check the above array and return something when the value "processing" of all the arrays equal 0 a.k.a false does that make more sense? Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212952 Share on other sites More sharing options...
Zurev Posted May 9, 2011 Share Posted May 9, 2011 foreach ($mainArray as $eachArray) { foreach ($eachArray as $key => $val) { if ($key=="processing" && $val==false) { // do action here break 2; // ends foreach loops } } } Did that help? Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212956 Share on other sites More sharing options...
The Little Guy Posted May 9, 2011 Author Share Posted May 9, 2011 here is what I have so far in my method: reset($this->threads); while(list($key, $thread) = each($this->threads)){ print_r($thread); $this->pollThread($thread['thread_id'], $output, $headers); if($thread['processing']){ $this->processing = true; } } Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212957 Share on other sites More sharing options...
Psycho Posted May 9, 2011 Share Posted May 9, 2011 With that array format, you have no option other than iterating over each of the array values to check if the sub-array has a processing of 0 or 1. However, if this array is coming from a DB query, then you should simply do an array to see if all of the target values have a processing value of 0. Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212958 Share on other sites More sharing options...
The Little Guy Posted May 9, 2011 Author Share Posted May 9, 2011 It is not coming from a db, It is coming from a script Quote Link to comment https://forums.phpfreaks.com/topic/235938-array-value-exists/#findComment-1212962 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.