Jump to content

[SOLVED] Arrays again


plutomed

Recommended Posts

the array:

<?php $main_nav = array(
	"names" => array("Home", "Pictures", "Templates", "Website Coding"),
	"pages" => array("index.php", "pictures.php", "templates.php", "website_coding.php")
); ?>

 

the breadcrub code I am going throught making:

<?php
$page = $_SERVER['PHP_SELF'];
$explode = explode("/", $page);
$counted = count($explode);
$i_i = 0;
while($i_i < $counted)
{
	if($i_i == $counted-1)
	{
		$sub_nav_data = sub_nav();
		$main_nav = main_nav();
		$search = array_keys($main_nav['pages'], $explode[$i_i]);
		//the line below is the one
		$search2 = in_array($search[0], $main_nav['names']);
		//the line above
		echo "<a href=\"".$explode[$i_i]."\">".$search2."</a>";
	}
	$i_i++;
} ?>

Link to comment
https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326314
Share on other sites

I think you want array_search() .. eg

 

<?php $main_nav = array(
                "names" => array("Home", "Pictures", "Templates", "Website Coding"),
                "pages" => array("index.php", "pictures.php", "templates.php", "website_coding.php")
        );
$find = 'Templates';
$index = array_search($find, $main_nav['names']);
print "$find uses the script {$main_nav['pages'][$index]}\n";
?>

Link to comment
https://forums.phpfreaks.com/topic/65338-solved-arrays-again/#findComment-326384
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.