![]() |
searching array
Hey guys/gals,
I am trying to output only the items in the array that have ISBN in it. I tried both array_search() and in_array() functions and each time I got errors for using invalid data types in the second field. Code:
<?phpWhat am I doing wrong? |
PHP Code:
when using echo to output data please the comma instead of the period to concatenate strings it is faster. when you're processing strings without variables in them use single quotes as PHP doesn't process them. Unless I'm mistaken standards mandate html be lowercase so <BR /> should <br /> P.S - I am not sure this would be the best method. |
You are using in_array incorrectly in the second sample code; You are iterating over a block of elements and pass the second parameter to in_array() as a string where it would expect an array, further though the first parameter for in_array() does not work as a wildcard, it will see if theres an element with that content in this case ISBN and nothing else, meaning it will always return false here.
What you need to do is to use something like str[i]str(): PHP Code:
|
If you want to go the regular expression route, there's another function which is much friendlier to arrays:
preg_grep.Example PHP Code:
Code:
Array |
Quote:
I guess I got the HTML mandate backwards, I thought it was all capitals.... Thanks for the code..... Quote:
*!* Quote:
As always thanks! |
Quote:
|
| All times are GMT. The time now is 06:28 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0