Jump to content

Recommended Posts

Hi all! Very new to php (current running php 4.4) and I am really getting into it!

 

I have been getting on fine with basic coding until I stumbled accross a problem. I cant seem to figure out how to check to see if a value in one array is in another array - and if so just simple report back "true" or "false".

 

Lets call the two arrays LOCKS and KEYS.

 

Doing a print_r($locks) would give:

 

Array ( [0] => 9 [1] => 17 [2] => 26 [3] => 27 [4] => 28 [5] => 31 [6] => 34 [7] => 38 [8] => 40 [9] => 41 [10] => 46 [11] => 49 [12] => 53 [13] => 54 [14] => 56 [15] => 60 [16] => 10 [17] => 11 [18] => 14 [19] => 19 [20] => 20 [21] => 22 [22] => 21 [23] => 23 [24] => 24 [25] => 25 [26] => 29 [27] => 30 [28] => 32 [29] => 33 [30] => 36 [31] => 37 [32] => 39 [33] => 42 [34] => 43 [35] => 44 [36] => 45 [37] => 47 [38] => 48 [39] => 50 [40] => 51 [41] => 52 [42] => 55 [43] => 58 [44] => 8 [45] => 12 [46] => 16 [47] => 18 [48] => 35 [49] => 59 [50] => 57 [51] => 13 [52] => 65 )

 

and doing a print_r($keys) would give:

 

Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 20 [4] => 65 )

 

What I want to do is jsut test to see if any value from the $key array is in the $lock array.

 

There maybe be more than one available but I just want it to report back a true or false value...

 

Any help would really be appreciated!

 

thanks!

 

Syto :)  :D;D

Link to comment
https://forums.phpfreaks.com/topic/65708-compare-items-in-an-array/
Share on other sites

I've just found out how to do and I have been doing it alot

 

the way I do it:

 

function main_nav()
{
$main_nav = array(
	"names" => array("Home", "Pictures", "Templates", "Website Coding", "Search"),
	"pages" => array("index.php", "pictures.php", "templates.php", "website_coding.php", "search.php"),
);


$count_main = count($main_nav['names']);
$i_main = 0;	

while($i_main < $count_main)
{
	$links_main .= " <a href=\"".$main_nav['pages'][$i_main]."\">".$main_nav['names'][$i_main]."</a> ";
	$i_main++;
}
echo $links_main;
}

 

That is an exaple of one of mine it might help....

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.