473,396 Members | 1,724 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,396 software developers and data experts.

Frustrated and confused

I have some code in which there are a bunch of objects. The objects
are in arrays. When checking one of the arrays for a number thats in
a variable in an object, I cant seem to get the search to work.
However I can get the search to work by putting in one instance of
that variable. But then comparing the two shows they're both the same.
I don't get how if they're both the same one works and one doesn't.
This is from inside one of the foreach statements:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (in_array($val->onumber,$ponum))
  3. echo "FOUND VARIABLE";
  4. if (in_array(358737,$ponum))
  5. echo "FOUND THE LITERAL";
  6. if ($val->onumber == 358737)
  7. echo "WHYWHYWHY";
  8.  
  9.  
The output is FOUND THE LITERALWHYWHYWHY. Why will it find the value
directly but not the variable, when it admits they're the same?

BTW, the in_array is just what I was using to check this. What I
really want to do is an array_search, that was doing the same thing.

Any suggestions?

Oct 31 '07 #1
6 1251
dysfunct wrote:
I have some code in which there are a bunch of objects. The objects
are in arrays. When checking one of the arrays for a number thats in
a variable in an object, I cant seem to get the search to work.
However I can get the search to work by putting in one instance of
that variable. But then comparing the two shows they're both the same.
I don't get how if they're both the same one works and one doesn't.
This is from inside one of the foreach statements:

Expand|Select|Wrap|Line Numbers
  1. if (in_array($val->onumber,$ponum))
  2.     echo "FOUND VARIABLE";
  3.     if (in_array(358737,$ponum))
  4.     echo "FOUND THE LITERAL";
  5.     if ($val->onumber == 358737)
  6.     echo "WHYWHYWHY";
  7.  

The output is FOUND THE LITERALWHYWHYWHY. Why will it find the value
directly but not the variable, when it admits they're the same?

BTW, the in_array is just what I was using to check this. What I
really want to do is an array_search, that was doing the same thing.

Any suggestions?

Can you try this and tell me what you get ?

if ($val->onumber === 358737)
echo "SEE, THEY ARE REALLY THE SAME";
Oct 31 '07 #2
Hmmm... got nothing. Whats going on here?
Oct 31 '07 #3
On Wed, 31 Oct 2007 04:18:23 +0100, dysfunct <Dy*********@gmail.comwrote:
Hmmm... got nothing. Whats going on here?
var_dump($val->onumber,$ponum); to the rescue....
--
Rik Wasmus
Oct 31 '07 #4
Yeah you guys are right, something is going on with the types. So I
made a search function:

function array_key_search($num, $array){
$found = array();
$n = 0;
foreach ($array as $k =$V){
settype($v,string);
echo gettype($v);
echo gettype($num);
if (strncasecmp($v,$num,6)==0){
$found[$n] = $k;
$n += 1;} }

return $found;
}

I added the echo gettype()'s in there just to see what it was
comparing and they both end up being strings in all cases. Still
doesn't wanna give me any results! I am befuddled.

Oct 31 '07 #5
I just did this:

function array_isearch($num, $array){
$found = array();
$n = 0;
foreach ($array as $k =$V){
settype($v,string);
echo "The ".gettype($v)." ".$v." does NOT equal ";
echo "the ".gettype($num)." ".$num."<br/>";
if (strncasecmp($v,$num,6)==0){
$found[$n] = $k;
$n += 1;} }

return $found;
}

The thing is, I'm getting "The string does NOT equal the string
[6digit number]." It's not picking up that value from the array...
hmm......

Oct 31 '07 #6
On Wed, 31 Oct 2007 14:02:21 +0100, dysfunct <Dy*********@gmail.comwrote:
I just did this:

function array_isearch($num, $array){
$found = array();
$n = 0;
foreach ($array as $k =$V){
settype($v,string);
echo "The ".gettype($v)." ".$v." does NOT equal ";
echo "the ".gettype($num)." ".$num."<br/>";
if (strncasecmp($v,$num,6)==0){
$found[$n] = $k;
$n += 1;} }

return $found;
}

The thing is, I'm getting "The string does NOT equal the string
[6digit number]." It's not picking up that value from the array...
hmm......

$V != $v

Please enable display_errors, and set error_reporting to E_ALL | E_STRICT.

And I'm still quite curious what the result of your var_dump was...
--
Rik Wasmus
Oct 31 '07 #7

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

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
3
by: MaryO | last post by:
I was hoping someone could help me with the OnNotInList function from Access. I downloaded this code below. I keep getting an error on the fAddToList – Sub or Function not defined. Please help...
9
by: Lyle Fairfield | last post by:
This is test, composed on my laptop while trying to repair my desktop? 1. Which is worse? Choose all that apply. a. Norton Anti-Virus b. A Virus c. Norton Anti-Spam d. Spam e. Norton...
6
by: garyusenet | last post by:
I have created a new project. and within this project as per the tutorial created an sql database. i have made a query which returns the result i need. 1. I cant SAVE THE QUERY? where on earth...
4
by: Ann | last post by:
I'm in a very frustrated situation now regarding to use jsp or asp.net. I'm a VBA programmer. Some of our web pages related with databases were setup in kind of old way , that is, in Access...
10
by: Don Wash | last post by:
Hi! I'm pretty frustrated learning ASP.NET. I'm learning ASP.NET by downloading samples from various ASP.NET websites and none of the samples worked so far. The SAME error was shown whenever I...
8
by: coleenholley | last post by:
I'm trying to format this bit of code into a numeric format of 12,123 no decimals in the particular format. Here's the code: tbl_worksheet1.Rows(b).Cells(2).Text() = Format(ls_sum_gasohol,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
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,...

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.