$myString = '293-52-8-39402';
$first = array_shift(explode('-', $myString));
The value of $first is 293.
How can I get the value of $last “39402”?
$myString = '293-52-8-39402';
$first = array_shift(explode('-', $myString));
The value of $first is 293.
How can I get the value of $last “39402”?
strrchr() and substr()
Here’s a way to do it, there are tons of ways but hey… lol
<?php
$myString = '293-52-8-39402';
$set = explode('-', $myString);
$first = array_slice($set, 0, 1);
$last = array_slice($set, -1, 1);
echo $first[0];
echo '<hr />';
echo $last[0];
// $first = $first[0]
// $last = $last[0]
another option
<?php
$myString = '293-52-8-39402';
echo substr(strrchr($myString,'-'),1);
?>