-1

Array ( [states] => Array ( [] => Select State [1] => Andaman and Nicobar (AN) [2] => Andhra Pradesh (AP) [3] => Arunachal Pradesh (AR) [4] => Assam (AS) [5] => Bihar (BR) [6] => Chandigarh (CH) [7] => Chhattisgarh (CG) [8] => Dadra and Nagar Haveli (DN) [9] => Daman and Diu (DD) [10] => Delhi (DL) [11] => Goa (GA) [12] => Gujarat (GJ) [13] => Haryana (HR) [14] => Himachal Pradesh (HP) [15] => Jammu and Kashmir (JK) [16] => Jharkhand (JH) [17] => Karnataka (KA) [18] => Kerala (KL) [19] => Lakshdweep (LD) [20] => Madhya Pradesh (MP) [21] => Maharashtra (MH) [22] => Manipur (MN) [23] => Meghalaya (ML) [24] => Mizoram (MZ) [25] => Nagaland (NL) [26] => Odisha (OD) [27] => Puducherry (PY) [28] => Punjab (PB) [29] => Rajasthan (RJ) [30] => Sikkim (SK) [31] => Tamil Nadu (TN) [32] => Telangana (TG) [33] => Tripura (TR) [34] => Uttar Pradesh (UP) [35] => Uttarakhand (UK) [36] => West Bengal (WB) )

[captcha_image] => 
[browser_details] => Chrome
[browser_version] => 75.0.3770.100
[user_ip_address] => ::1
[0] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[1] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[2] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[3] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[4] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[5] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[6] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[7] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[8] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[9] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[10] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[11] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[12] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[13] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[14] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[15] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[16] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[17] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[18] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[19] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[20] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[21] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[22] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[23] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[24] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[25] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[26] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[27] => stdClass Object
    (
        [date_added] => 0000-00-00 00:00:00
    )

[28] => stdClass Object
    (
        [date_added] => 2019-07-08 15:14:38
    )

)

  • 1
    Possible duplicate of [How to get last key in an array](https://stackoverflow.com/questions/2348205/how-to-get-last-key-in-an-array) – Ajanyan Pradeep Jul 09 '19 at 07:15
  • Please provide proper indentation of your sample input. Also, what is the expected output? What have you tried(although this question has lost it's value)? – nice_dev Jul 09 '19 at 07:37

2 Answers2

1

1- i want to access the last key and value how it is possible?

<?php
    //Append the array value in variable $array, After that follow the below step.
      end($array['states']); // The end() function moves the internal pointer to, and outputs, the last element in the array.

        $key = key($array['states']);  // get the last key
        echo $value = $array['states'][$key]; // get last value be key
        ?>

DEMO

2- Ans based on comments 'how can i access each value particularly of object array?'

//Append your object_array in variable call array
$array = object_array; 
//Using loop you can get the value of object. 
foreach ($array as $value) { 
echo $value->date_added ; 
} 
Shivendra Singh
  • 2,986
  • 1
  • 11
  • 11
  • Thank you so much. Bt I do not want to use end function because it gives me the access of last index.. I want to access the all the stdclass objects ohk – Sagar Verma Jul 09 '19 at 07:29
  • In Question you mention i want to access the last key and value how it is possible? – Shivendra Singh Jul 09 '19 at 07:31
  • Yess but also want that how? Sorry for my mistake – Sagar Verma Jul 09 '19 at 07:33
  • I think you talking about second object array. i'm right? – Shivendra Singh Jul 09 '19 at 07:34
  • [0] => stdClass Object ( [date_added] => 0000-00-00 00:00:00 ) [1] => stdClass Object ( [date_added] => 0000-00-00 00:00:00 ) [2] => stdClass Object ( [date_added] => 0000-00-00 00:00:00 ) [3] => stdClass Object ( [date_added] => 0000-00-00 00:00:00 ) [4] => stdClass Object ( [date_added] => 0000-00-00 00:00:00 ) form till last how can i access each value particularly? – Sagar Verma Jul 09 '19 at 07:36
  • For this you have need to use foreach loop to get the value - like $array = object_array; foreach ($array as $value) { echo $value->date_added ; } – Shivendra Singh Jul 09 '19 at 07:40
  • Now you are getting the object value.? – Shivendra Singh Jul 09 '19 at 10:50
0

Try this

 end($array['states']);
 $z = prev($array['states']);
nageen nayak
  • 1,262
  • 2
  • 18
  • 28