A function that tells whether a given element can be found in an array. Use this tag for question related to in-array.
0
votes
1answer
10 views
if(in_array()) not working in Wordpress
I am using Wordpress latest version and I this piece of code inside my header.php:
<?php
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$slugMenu = array (
'planes',
...
-2
votes
2answers
44 views
jQuery $.inArray still passing value even if it checked for existence [on hold]
I am using $.inArray to check if value is in array. if it is not I want to add it, else do nothing.
var arrayValues = [1];
for (var i = 1; i <= 3; i++) {
if($.inArray('1', arrayValues) === ...
0
votes
2answers
10 views
Javascript: Get the array where a specific value in the array contains word (tags)
I have this array:
[{
"title": "Pirates of the Caribbean 5",
"others": "lorem",
"tags": "action,experimental,comedy"
},
{
"title": "Toy Story 3",
"others": "lorem",
"tags": ...
0
votes
1answer
32 views
Search if an element exists in a associative array
I have an loop as below:
for( $m = 0; $m < count( $spcl_holiday_list_r ); $m++ )
{
$region_str = $spcl_holiday_list_r[$m]['region'];
$region_arr = explode(",",$region_str);
...
1
vote
1answer
44 views
Using in_array with currency symbol?
I'm working on a PHP file which can echo a price (given by an array from another website) converted in a certain currency (let's say in € for example).
I thought about using the in_array function to ...
0
votes
1answer
39 views
PHP - Find nested array1 in nested array2
I need to look through Array1, finding any matching sequences from Array2, and update corresponding sub-arrays in Array1.
I previously had help on a similar question;
Find array in array, in sequence
...
0
votes
5answers
38 views
How can I know the key of my array when I know the value?
I have a multiple-array :
$bouton["modify-customer"] = array("fr"=>"liste-client", "en"=>"customer-list");
$bouton["create-customer"] = array("fr"=>"creer-client", ...
0
votes
2answers
31 views
php, in_array and serialize() not working as expected [closed]
I have a list of contact for friends in a database, what I am trying to do is retrieve a users contacts, see if the other user id is in there, if it is not then add it then put it back in the ...
1
vote
2answers
60 views
in_array() does not seem to check after key 2
I have a simple function that should just give me TRUE or FALSE if a value is find in an array.
function bypass($user, $bypassUsers){
$users = explode(",", $bypassUsers);
// trim($users);
...
4
votes
4answers
77 views
in_array returns true if needle is 0
I have an issue with in_array function. Test below returns true:
in_array(0, array('card', 'cash'))
How is it impossible, how can I prevent it ?
However
in_array(null, array('card', 'cash'))
...
-2
votes
1answer
49 views
php in_array() or array_search() not working [duplicate]
I am using a simple php script to look for an element in an array like
$restricted = array('root/base', 'root2' );
print_r($restricted);
if( array_search('root/base', $restricted) ){
...
1
vote
1answer
39 views
Remove previous element from array if statement == true
I have a foreach loop that iterates through an array but I want to check if the array contains $item == 'survey-east-upper' and if that's true then hide the previous $item which is 'survey-east'. I've ...
1
vote
1answer
36 views
PHP: If String[Index] is in Array, PHP: String from String[1] to String[last]
Is there a PHP call for in_str?
…something similar to in_array..
Am using an if-else to take the each word (string) in the array of strings (from a form-input-text) to see if the start index [0] is ...
-1
votes
2answers
107 views
Warning: in_array() expects parameter 2 to be array [closed]
I read the php in_arraymanual and create some code lines.
$handle = fopen("/path/to/file", "a") or die('Cannot open file:');
$y= $command_name1.$steps1;
$x=trim(shell_exec("grep -ri -o ...
1
vote
5answers
132 views
PHP Count Number of True Values in a Boolean Array
I have an associative array in which I need to count the number of boolean true values within.
The end result is to create an if statement in which would return true when only one true value exists ...
-2
votes
3answers
56 views
in_array with repeating variable [closed]
I am using in_array function of php to get particular variable and display its image upon finding it in the array. I have 3 such variables which can be displayed. But in an array there could be a ...
0
votes
2answers
66 views
in_array works for the first time in checkbox
A strange issue. this is the array with some values
$et_er_facilities = ( [0] => Swimming pool
[1] => Squash court
[2] => Mini market
[3] => Playground )
If I add a few checkboxes ...
0
votes
3answers
73 views
select result except strings in_array with sql
I have code like this:
$p = $db->query("SELECT ads_id FROM ads_submissions WHERE status = '0'");
$c_ads = array();
while($row = $db->fetchAll($p))
{
$c_ads[] = $row;
}
Output
4 6 9
I ...
0
votes
2answers
160 views
PHP if in_array for multiple values
I have an array that is generated with anywhere between 3 and 12 values, it generates the array from account information;
$result = $ad->user()->groups($user['username']);
I want to check ...
0
votes
3answers
92 views
Issue with two stage in_array checking, wont allow second statement to be processed
Background:
I am creating a method to pull information from one table, check if it exists in a second table, and if it doesn't then insert the information. While comparing the data, the check must ...
0
votes
2answers
30 views
Check variable is the plural of an array value
I want to run an in_array and return true if the variable is a plural version of an array value. I don't want to add the plurals of each word to the array.
$username = 'admins';
$blacklist = [
...
2
votes
2answers
74 views
Problems using in_array and date in if/else
I am experimenting with the date and in_array functions of PHP.
Based on what I have read in the manual I can't understand why my code is returning the else part of the if statement. If the date('D') ...
0
votes
2answers
62 views
in_array function not working right
I am using a multidimensional array to hold the variables for a given page. I am trying to get a string from the url and match it with an array within my template array to pull the correct variables ...
0
votes
1answer
42 views
search for value in array
I am modifying an old question, not sure if this is the right way.
This is the code I have
Array ( [0] => Gymnasium [1] => Mini market [2] => Jogging track )
What I need to do is search ...
0
votes
1answer
26 views
Curious problème with images upload in PHP from form
I try to upload pictures from a form in PHP.
I've got a strange problem regarding my images upload:
My form:
<form id="booking-step" method="post" action="add.php" class="booking" ...
0
votes
3answers
66 views
Checks if several values exists in an array
I want check if exists several values (EX: 5,110) in array return is true. (without use loop)
I don't use from loop because i want load a page if return was true
AS:
if(in_array('5' OR '110', ...
11
votes
4answers
218 views
PHP in_array comparision working differently on different machine
Please review following piece of code, it is giving different results on different machines:
$data = array(
"28000000000000003" => 'ABC',
"28000000000000001" => 'PQR'
);
echo ...
2
votes
1answer
174 views
How to check if an element exists in a Python array (Equivalent of PHP in_array)?
I'm new to Python and I'm looking for a standard function that would tell me if an element is present in an array. I found the index method but it throws an exception if the element is not found. I ...
0
votes
3answers
70 views
php, efficient way to determine if this value is in my array [duplicate]
Possible Duplicate:
Find values in multidimensional arrays
This is my array, it contains an array of key value pairs.
[
{
valueA: 0,
valueB: 0,
day: "2010-04-09"
},
{
...
0
votes
1answer
24 views
Which is faster/better to store collection of strings in PHP
I am trying to create an array to store which nodes I have visited before. The nodes will be uniquely represented by a string, and the string can be very long. Hence, I am wondering which of the two ...