0

From this array:

array(3) { 
    ["news_status"]=> string(1) "1" 
    ["news_input_title"]=> string(10) "test title" 
    ["news_input_description"]=> string(61) "<p>test description over 20 symbols<br></p>" 
} 

I want to get

["news_status"]=> string(1) "1" 

but to look exactly same (to be array(1)), something like this :

array(1) { 
    ["news_status"]=> string(1) "1" 
}

most functions like reset, current get only value ..

5
  • foreach($array as $key=>$value) Commented Jun 21, 2017 at 8:37
  • 1
    But i want only first element, like array.. Commented Jun 21, 2017 at 8:37
  • 1
    foreach ($this->request->post as $key => $value){ $ss[$key] = $value; break; } i try with this but it's not very good, i think Commented Jun 21, 2017 at 8:40
  • 1
    $result = array_slice($array, 0, 1, true); This is a pretty strange thing to want to do though - if you always want the first element, then you must know which key it is, or it wouldn't be any use. Commented Jun 21, 2017 at 8:42
  • 1
    Yeah, that's it, THANK U ! Commented Jun 21, 2017 at 8:44

1 Answer 1

2

Try $first_element = array_slice( $myArray , 0 , 1 )

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.