-1

I want to get value from an array like this..

Array
(
    [0] => May 2019 1
    [1] => May 2019 14
)

I need to get just 1 and 14 from this array Thanks in advance!

  • @pc-shooter I think what he means it "*I want to extract the last number of every item in this array*". That'd be `1` and `14`. – h2ooooooo May 08 '14 at 11:22
  • @h2ooooooo but still 43'892 results... and no help? I mean, have a look at the answers, familiary, aren't they? – toesslab May 08 '14 at 11:23

4 Answers4

1

try this

$arr = array('your array');
foreach($arr as $v)
{
    $date = end(explode(' ',$v));
    //do your stuff

}
shatheesh
  • 633
  • 6
  • 10
0

Use array_map() , array_pop() and explode()

$dates = array_map(function ($v){
    $v = explode(' ',$v); //<--- Explodes your array using a space
    return array_pop($v); //<--- Grabs the last element and returns to your $dates array.
},$yourarray);

Demonstration

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • 1
    Looking at the OP's question and your answer, I don't think he will understand this. A combination of `array_map()` and `array_pop()` is harder to understand and read than for example a `foreach()` loop with the `end()` function. – Ron van der Heijden May 08 '14 at 11:44
0

Try this ,

 $myarray    =   array('Monday, 06. May 2019 1','Sunday, 19. May 2019 14');

 foreach($myarray as $str){
     $split = explode(" ", $str);
     echo $split[count($split)-1].'</br>';
  }
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45
0

As said by @pc-shooter this has been answered loads already, a quick Google gives the answer too. how-to-get-single-value-from-php-array

echo $array[1].$array[14];

Community
  • 1
  • 1
CygnusH33L
  • 21
  • 2
  • Not what he asked, though. This would give you `Sunday, 19. May 2019 14` and an undefined index notice. – h2ooooooo May 08 '14 at 11:24
  • So why you answer it then? – toesslab May 08 '14 at 11:24
  • h2oooooo ok yeah i'm wrong :/ PC-shooter just because, I'm trying to get more rep so I can up-vote answers I find helpful when researching myself. I have used Stack for years to help me but never been able to up-vote as a thanks. (never needed to ask a question though, always find what I'm after through searches) – CygnusH33L May 08 '14 at 11:28
  • @CygnusH33L Ok I must admit, I did that too – toesslab May 08 '14 at 11:42