hi i need to compare a value inside the array that is returned via recordset from database -
Array
-
(
-
[0] => Array
-
(
-
[email] => ranatouqeer@msn.com
-
)
-
-
[1] => Array
-
(
-
[email] => omer@etgi.us
-
)
-
-
)
-
i am trying to use in_array() to search inside the array but in_array() doesnt seem to do so here is the code -
$email=$this->input->post('email');
-
if(in_array($email,$newsletter_array)){
-
echo 'yes';
-
}else{
-
echo 'no';
-
}
-
i have tried using it this way too -
if(in_array(array(array('email'=>$email)),$newsletter_array)){
-
echo 'yes';
-
}else{
-
echo 'no';
-
}
-
what am i doing wrong
regards,
Omer Aslam
i did it by using the following method -
function array_value_recursive($key, array $arr){
-
$val = array();
-
@array_walk_recursive($arr, function($v, $k) use($key, &$val){ if($k == $key) array_push($val, $v);});
-
return count($val) > 1 ? $val : array_pop($val);
-
}
-
$new_array=array_value_recursive('email',$newsletter_array);
-
-
if(in_array($email,$new_array)){
-
echo 'matched';
-
}else{
-
echo 'not found';
-
}
-
regards,
Omer Aslam
1 1430
i did it by using the following method -
function array_value_recursive($key, array $arr){
-
$val = array();
-
@array_walk_recursive($arr, function($v, $k) use($key, &$val){ if($k == $key) array_push($val, $v);});
-
return count($val) > 1 ? $val : array_pop($val);
-
}
-
$new_array=array_value_recursive('email',$newsletter_array);
-
-
if(in_array($email,$new_array)){
-
echo 'matched';
-
}else{
-
echo 'not found';
-
}
-
regards,
Omer Aslam
Sign in to post your reply or Sign up for a free account.
Similar topics
by: AJ Z |
last post by:
I am using in_array() to search for a value ("other"), in order to validate
a form.
If I pass $_POST as the array to search PHP says that it is an
invalid datatype.
It is an array and if I copy...
|
by: Mountain Man |
last post by:
Hi,
The in_array function sometimes malfunctions on my computer yielding
the error message shown below. The code shown below usually works, but
sometimes doesn't. This even happens with the same...
|
by: Phil Powell |
last post by:
if (is_array($_POST)) {
foreach ($this->getAssocSectionsObjArray($key, $dbAP) as
$obj) {
print_r($obj); print_r(" in array? ");
print_r(in_array($obj, $result)); print_r("<P>");
if...
|
by: Craig Keightley |
last post by:
I am trying to compare values of a string entered into an array but having
no results, is this possible to achieve:
<?php
$ids = $row_rsProduct; // A comma separated list of values...
|
by: Phil Powell |
last post by:
Here is my array. Plain and simple enumerative array with values
being strings.
So why does this fail???
print_r(in_array('album', array_keys($boolword)));
This produces FALSE or NULL....
|
by: paul brown |
last post by:
hello,
I have this code sample:
class Sexboard extends Master
{
var $userid;
var $errormessage;
var $dc_metro = array(20, 46, 51);
|
by: Tom Barnes |
last post by:
Check out this code:
// Start Code -------------
function test_in_array($val)
{
$a = array('key' => $val);
printf("in_array: %d, value:%s<BR>", in_array('key', $a), $a);
}
test_in_array(0);...
|
by: Berimor |
last post by:
Hi,
i've been always used the in_array() function to check availabylity of a
value in array. Until today. Simple code: (do not run it tho :) )
<?
function getmicrotime(){
list($usec, $sec) =...
|
by: rich |
last post by:
I keep getting the error:
Warning: in_array(): Wrong datatype for second argument on line 679
here is the code.
I declare and fill the array
$specprimA = array();
$specprimA=...
|
by: Sonnich |
last post by:
The following code is an exact copy of my current code.
The idea is to check 2 parts (of string arrays), and add those only
once to a common array.
I check for existance of an array in a string,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |