Help with PHP/HTML Foreach loop and array


#1

Hi! i have an issue with using the “stristr” in the foreach loop. I want to loop trough an array, and get the values in to a new array if one or more letters are contained in the “v2” array. so for instance if $a=“C” then “$funn” would contain all the elements witch contains the letter “C”. like “BTC”, and “LTC” and so on. can anybody help?
[php]
v2 = array(
“BTC” => Array(
“navn” =>“Bitcoin”,
“k1”=>1,
“k2”=>11,
“k3”=>17
),
“ETH” => Array(
“navn”=>“Ethereum”,
“k1”=>1000,
“k2”=>12,
“k3”=>27
),
“LTC” => Array(
“navn”=> “Litecoin”,
“k1”=> 62,
“k2”=>13,
“k3”=>37
),
“XMR” => Array(
“navn”=>“Monero”,
“k1”=>51,
“k2”=>14,
“k3”=>47
),
“XRP” => Array(
“navn”=> “Ripple”,
“k1”=>31,
“k2”=>15,
“k3”=>57
)
);

a=“C”
$funn=array();
foreach($v2 as $key => $leteord){

if (stristr($a, $key)=== true) {
	$funn=array($key);
}

}
echo “

”;
print_r ($funn);
echo “
”;
[/php]

#2

You have some things backwards.

https://www.ideone.com/5ygW09
stristr()


#3

Thank you so much! You made my day :smiley: