Jump to content

problem in array


yolop

Recommended Posts

$search = 'c6';
$str = '111c6,vvvc6222,c6c6,444c6';
$parts = explode(',', $str);
$sizeof = sizeof($parts);
for ($i = $sizeof - 1; $i >= 0; --$i) {
    if (false !== strpos($str, $parts[$i])) {
        print $parts[$i]; break;
    }
}

Link to comment
https://forums.phpfreaks.com/topic/172981-problem-in-array/#findComment-911685
Share on other sites

<?php
function getLastIndex($a,$s) {
	$a = array_reverse($a,true);
	foreach ($a as $k => $v) {
		if (strpos($v,$s) !== false) return $k;
	}
	return false;
}
$array = array('abcd1','cdef','gpd1');
$key = getLastIndex($array,'d1');
// $key should equal 2
?>

Link to comment
https://forums.phpfreaks.com/topic/172981-problem-in-array/#findComment-911686
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.