1

I have an array structure like this:

$data=    Array
    (
        [1] => Array
            (
                [A] => BANK
                [B] => IFSC
                [C] => MICR
                [D] => BRANCH
                [E] => ADDRESS
                [F] => CONTACT
                [G] => CITY
                [H] => DISTRICT
                [I] => STATE
            )

        [2] => Array
            (
                [A] => ABHYUDAYA COOPERATIVE BANK LIMITED
                [B] => ABHY0065001
                [C] => 400065001
                [D] => RTGS-HO
                [E] => ABHYUDAYA BANK BLDG., B.NO.71, NEHRU NAGAR, KURLA (E), MUMBAI-400024
                [F] => 25260173
                [G] => MUMBAI
                [H] => GREATER MUMBAI
                [I] => MAHARASHTRA
            )

        [3] => Array
            (
                [A] => ABHYUDAYA COOPERATIVE BANK LIMITED
                [B] => ABHY0065002
                [C] => 400065002
                [D] => ABHYUDAYA NAGAR
                [E] => ABHYUDAYA EDUCATION SOCIETY, OPP. BLDG. NO. 18, ABHYUDAYA NAGAR, KALACHOWKY, MUMBAI - 400033
                [F] => 24702643
                [G] => MUMBAI
                [H] => GREATER MUMBAI
                [I] => MAHARASHTRA
            )
    )

I want to delete the first index,and reindex the array from 0.

I tried the following: $newData = array_splice($data,0,1);

but it gives the following output

Array
(
    [0] => Array
        (
            [A] => BANK
            [B] => IFSC
            [C] => MICR
            [D] => BRANCH
            [E] => ADDRESS
            [F] => CONTACT
            [G] => CITY
            [H] => DISTRICT
            [I] => STATE
        )

)

The Part of array that I want to remove is the one that stays and the remaining is deleted.

2
  • $newData = array_slice($data,1); Commented May 1, 2017 at 10:51
  • thank you .This did the job Commented May 1, 2017 at 10:53

4 Answers 4

1

You can use array_slice($array, 1).

$result = array_slice($data, 1);
print_r($result);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use array_shift() for that. When using numerical keys, they are automatically reset so that is all you need:

$first = array_shift($data);
// or just: array_shift($data);
var_dump($data);

Comments

0

Why don't you use array_shift(). It Remove the first element from an array, and return the value of the removed element:

<?php
$a=array("a"=>"red","b"=>"green","c"=>"blue");
echo array_shift($a)."<br>";
print_r ($a);
?>

Output will be this

red
Array ( [b] => green [c] => blue ) 

Comments

0

Try this simple one.. hope this will help you out. Here we are using key function which will return first key, Here we are unsetting top index and returning array_values.

Try this code snippet here

unset($data[key($data)]);//unsetting the top index
$data=array_values($data);//returning array_values
print_r($data);

Output:

Array
(
    [0] => Array
        (
            [A] => ABHYUDAYA COOPERATIVE BANK LIMITED
            [B] => ABHY0065001
            [C] => 400065001
            [D] => RTGS-HO
            [E] => ABHYUDAYA BANK BLDG., B.NO.71, NEHRU NAGAR, KURLA (E), MUMBAI-400024
            [F] => 25260173
            [G] => MUMBAI
            [H] => GREATER MUMBAI
            [I] => MAHARASHTRA
        )

    [1] => Array
        (
            [A] => ABHYUDAYA COOPERATIVE BANK LIMITED
            [B] => ABHY0065002
            [C] => 400065002
            [D] => ABHYUDAYA NAGAR
            [E] => ABHYUDAYA EDUCATION SOCIETY, OPP. BLDG. NO. 18, ABHYUDAYA NAGAR, KALACHOWKY, MUMBAI - 400033
            [F] => 24702643
            [G] => MUMBAI
            [H] => GREATER MUMBAI
            [I] => MAHARASHTRA
        )

)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.