I'm trying to search an array for a string and if the string exists in the array it wont go into the if statement, I'm using the below code, It just wont work for me, any ideas? - if((!in_array($string,$Array)) && ($string != '')) {
-
print $string.'<br/>';
-
}
11 1868
This is what I do, would that be practical? -
-
if ( in_array ( $string, $array) ){
-
echo 'The ' .$string. ' is in the array';
-
}
-
else
-
{
-
echo 'The ' .$string. ' is not in the array';
-
}
-
-
Dormilich 8,658
Recognized Expert Moderator Expert @ziycon
translated into words:
if string is not in array and string is not empty then print string.
...exactly what has happened.
although I'd test for the string first (the second expression is not executed if the first expression evaluates to FALSE) - if ($string && in_array(...))
Basicly if the string doesn't exist in the array and the string isn't empty then it will print out but whats happening is even if the string is in the array it still prints out the string, which it shouldn't do!
Dormilich 8,658
Recognized Expert Moderator Expert
can you give an example to reproduce, because that sounds unlikely?
$outputArrayTemp[$outputCountTemp] has just been assigned a string.
The strings would be links like 'http://www.google.ie' etc. - if((!in_array($outputArrayTemp[$outputCountTemp],$outputArrayTemp)) && ($outputArrayTemp[$outputCountTemp] != '')) {
-
print $outputArrayTemp[$outputCountTemp].'<br/>';
-
$outputCountTemp++;
-
}
Ok, heres what I have so far, the full function. Hopefully this makes it easier to understand what I'm trying to do. Any help is much appreciated. - $linkCount = sizeof($matches[1]);
-
-
while($count < $linkCount) {
-
$string = $matches[1][$count];
-
-
if($string[0] == '/') {
-
$outputArrayTemp[$outputCountTemp] = $domain.$string;
-
$outputCountTemp++;
-
}
-
else if(substr($string,0,4) == 'http') {
-
$outputArrayTemp[$outputCountTemp] = $string;
-
$outputCountTemp++;
-
}
-
-
if((!in_array($outputArrayTemp[$outputCountTemp-1],$outputArrayTemp)) && ($outputArrayTemp[$outputCountTemp-1] != '')) {
-
$outputArray[$outputCount] = $outputArrayTemp[$outputCountTemp-1];
-
$outputCount++;
-
}
-
$count++;
-
}
Dormilich 8,658
Recognized Expert Moderator Expert
did you define the start values of $outputCountTemp and $count anywhere?
There both defined as zero, think I have it working withe the below code: - $linkCount = sizeof($matches[1]);
-
-
while($count < $linkCount) {
-
$string = $matches[1][$count];
-
-
if(($string[0] == '/') || (substr($string,0,4) == 'http')) {
-
if($string[0] == '/') {
-
$outputArrayTemp[$outputCountTemp] = $domain.$string;
-
$outputCountTemp++;
-
}
-
else if(substr($string,0,4) == 'http') {
-
$outputArrayTemp[$outputCountTemp] = $string;
-
$outputCountTemp++;
-
}
-
-
if(!in_array($outputArrayTemp[$outputCountTemp-1],$outputArray)) {
-
$outputArray[$outputCount] = $outputArrayTemp[$outputCountTemp-1];
-
$outputCount++;
-
}
-
}
-
$count++;
-
}
Dormilich 8,658
Recognized Expert Moderator Expert - !in_array($outputArrayTemp[$outputCountTemp-1],$outputArrayTemp)
this will always evaluate to false
@Dormilich
I know, I fixed it, was meant to be: - !in_array($outputArrayTemp[$outputCountTemp-1],$outputArray)
That was the main problem with it not working as far as I can tell.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Nico |
last post by:
Hello folks,
I am currently storing a set of objects inside an array,
$itemlist = array();
$itemlist = new item("myitem");
//...
and I am looking to develop a search function, which...
|
by: deko |
last post by:
I need to create a basic one-dimensional array of strings, but I don't know
how many strings I'm going to have until the code is finished looping.
pseudo code:
Dim astrMyArray()
Do While Not...
|
by: cyrvb |
last post by:
Hello,
I'm a very very newbie in C# I did start 2 days ago, I get Visual
Stuido 2005 C#
I try to understand how to manage the arrays
I did write this
|
by: alanbe |
last post by:
I am working on some scripts to help me automate the website creation
process.
I want to use a template for the whole website and call pages using
something like
...
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these...
| |
by: Bob Rock |
last post by:
Hello,
I have an array of strings and need to find the matching one with the
fastest possible code. I decided to order the array and then write a binary
search algo.
What I came up with is the...
|
by: ianenis.tiryaki |
last post by:
well i got this assignment which i dont even have a clue what i am
supposed to do. it is about reading me data from the file and load
them into a parallel array here is the question:
Step (1)
...
|
by: Akhenaten |
last post by:
I have an array created but I need to search it. The array is created
from a mysql call. Code as follows:
******************
function respond_check($qid)
{
include "db.inc.php";
$postchk2 =...
|
by: AZRebelCowgirl73 |
last post by:
Here is my problem:
I have two java files:
One named Car.java and the other named CarDealerApp.java: In the CarDealerApp program, I read in through user input the make, model, year and price of...
|
by: Robert Bevington |
last post by:
Hi all,
I ran into memory problems while tying to search and replace a very large
text file. To solve this I break the file up into chunks and run the search
and replace on each chunk. This...
|
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,...
| |
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |