473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

in_array() fails but it's in the array

array_keys($boolword) = Array ( [0] => 'album' [1] => 'keywords' [2]
=> 'persons' [3] => 'events' [4] => 'image_alt' [5] =>
'image_creation_start_date' [6] => 'image_creation_end_date' [7] =>
'image_location_city' [8] => 'image_location_state' [9] =>
'image_location_country' )
Here is my array. Plain and simple enumerative array with values
being strings.

So why does this fail???

[PHP]
print_r(in_array('album', array_keys($boolword)));
[/PHP]

This produces FALSE or NULL. But it's right there IN the array!! What
on earth is going on? Is this a failure in the part of in_array() that
I am unaware of?

This is a major showstopper in my search code PHP script I'm writing
for my application, please help someone!

Thanx
Phil
Jul 17 '05 #1
5 2355
have you tried with the proper syntax?

array_keys($boolword) = Array ( [0] => 'album',
[1] => 'keywords',
[2] => 'persons',
[3] => 'events',
[4] => 'image_alt',
[5] => 'image_creation_start_date',
[6] => 'image_creation_end_date',
[7] => 'image_location_city',
[8] => 'image_location_state',
[9] => 'image_location_country' );

R

--
Due to VERY heavy spam reception (24,000+/week), I use a fake address.
Please write me in this newsgroup if you want to get in contact with me

NEVER support spammers or companies sending out spam
NEVER use links sent to you in a spam mail
NEVER unsubscribe a spam message
NEVER reply to spam

"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om...
> array_keys($boolword) = Array ( [0] => 'album' [1] => 'keywords' [2]
=> 'persons' [3] => 'events' [4] => 'image_alt' [5] =>
'image_creation_start_date' [6] => 'image_creation_end_date' [7] =>
'image_location_city' [8] => 'image_location_state' [9] =>
'image_location_country' )

Here is my array. Plain and simple enumerative array with values
being strings.

So why does this fail???

[PHP]
print_r(in_array('album', array_keys($boolword)));
[/PHP]

This produces FALSE or NULL. But it's right there IN the array!! What
on earth is going on? Is this a failure in the part of in_array() that
I am unaware of?

This is a major showstopper in my search code PHP script I'm writing
for my application, please help someone!

Thanx
Phil

Jul 17 '05 #2
Phil Powell a écrit:
> array_keys($boolword) = Array ( [0] => 'album' [1] => 'keywords' [2]
=> 'persons' [3] => 'events' [4] => 'image_alt' [5] =>
'image_creation_start_date' [6] => 'image_creation_end_date' [7] =>
'image_location_city' [8] => 'image_location_state' [9] =>
'image_location_country' )

Here is my array. Plain and simple enumerative array with values
being strings.

So why does this fail???

[PHP]
print_r(in_array('album', array_keys($boolword)));
[/PHP]


What is $boolword ? it's inconsistent here, just place the name of the
array as second arg : print_r(in_array('album', array_keys));

Jul 17 '05 #3
In article <1c**************************@posting.google.com >,
so*****@erols.com (Phil Powell) wrote:
> array_keys($boolword) = Array ( [0] => 'album' [1] => 'keywords' [2]
=> 'persons' [3] => 'events' [4] => 'image_alt' [5] =>
'image_creation_start_date' [6] => 'image_creation_end_date' [7] =>
'image_location_city' [8] => 'image_location_state' [9] =>
'image_location_country' )

Here is my array. Plain and simple enumerative array with values
being strings.

So why does this fail???

[PHP]
print_r(in_array('album', array_keys($boolword)));
[/PHP]


You probably mean something like this:

$boolword = array('album', 'keywords', ...);

var_dump(in_array('album', $boolword));

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #4
No, sorry I meant exactly this:

Expand|Select|Wrap|Line Numbers
  1. $html .= "<select name=\"boolword['album']\">\n";
  2. ....
  3.  
And to handle it I would parse $_POST out to get $boolword and you get
this:

Expand|Select|Wrap|Line Numbers
  1. print_r($boolword);
  2.  
Results:

Array ('album' => 'AND', 'location' => '', 'image_name' => 'OR',
'whatever' => '')
Sorry I wasn't more clear. $boolword will be an associative array
whose keys are string values that are dynamically generated from the
name of the HTML form dropdown element 'boolword[something]'; the
value being a boolean word.

Problem is this: If I try to reference $boolword[$elementName] where
$elementName = 'album', it fails:

Expand|Select|Wrap|Line Numbers
  1. print_r($boolword[$elementName]);
  2.  
Results: NULL

However, if I reference $boolword["'$elementName'"] where $elementName
= 'album', it works perfectly:

Expand|Select|Wrap|Line Numbers
  1. print_r($boolword["'$elementName'"]);
  2.  
Results: AND

This is what I'm trying to convey. The associative array $boolword
produces an array where the keys seem to have embedded single quotes
inside the keys themselves!! Is this a PHP bug?

Phil

Jan Pieter Kunst <de*****@cauce.org> wrote in message news:<de***************************@news1.news.xs4 all.nl>...
In article <1c**************************@posting.google.com >,
so*****@erols.com (Phil Powell) wrote:
> > array_keys($boolword) = Array ( [0] => 'album' [1] => 'keywords' [2]
=> 'persons' [3] => 'events' [4] => 'image_alt' [5] =>
'image_creation_start_date' [6] => 'image_creation_end_date' [7] =>
'image_location_city' [8] => 'image_location_state' [9] =>
'image_location_country' )

Here is my array. Plain and simple enumerative array with values
being strings.

So why does this fail???

[PHP]
print_r(in_array('album', array_keys($boolword)));
[/PHP]


You probably mean something like this:

$boolword = array('album', 'keywords', ...);

var_dump(in_array('album', $boolword));

JP

Jul 17 '05 #5
In article <1c*************************@posting.google.com> ,
so*****@erols.com (Phil Powell) wrote:
Expand|Select|Wrap|Line Numbers
  1.  $html .= "<select name=\"boolword['album']\">\n";
  2.  ...
  3.  

[...]
This is what I'm trying to convey. The associative array $boolword
produces an array where the keys seem to have embedded single quotes
inside the keys themselves!! Is this a PHP bug?

Phil


No, it's because you put the single quotes in the HTML. If you want to
use [] syntax to get an array into $_REQUEST, you can either do this:

<select name="boolword[]">

for a numeric array $_REQUEST['boolword'], or this:

<select name="boolword[album]">

for an associative array $_REQUEST['boolword']. You shouldn't quote the
array key in the HTML. Quoting array keys is only needed in PHP code.

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
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...
3
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...
6
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...
3
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);...
6
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) =...
3
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=...
0
by: rich | last post by:
I have 2 arrays. I am trying to use in_array with and it doesn't seem to be working. I have done a print_r of each one for my test data. Array $primsecA is below: Array ( =Array ( =1 ...
3
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,...
3
by: GarryJones | last post by:
I want to add an value to an array if it is not already there. There are four values. Something is misfiring as it as the value to the array even if it is already there. The values are...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.