Dr. Banana
Dr. Banana

Reputation: 435

1 line of array to string php

I have the following array under $hashes:

Array
    (
        [0] => Array
            (
                [0] => "8b4bc4be1c7b2e5175b645ec6280" target="btcad"
                [1] => "4667fb10d39cc20e33fc8f60c4f4" target="btcad"
                [2] => "a98b3a8f093d0160614d28f541fb" target="btcad"
                [3] => "3c6f41fe78b58d94669d4f52e9be" target="btcad"
                [4] => "896c86451ceb88ea26291d2b6f4b" target="btcad"
                [5] => "e64a32b1e9e6978d2da38052832e" target="btcad"
                [6] => "74fe5907ab42a2610e3a6f42104e" target="btcad"
            )

    )

Now I also have a other variable named $selected which is a number, lets say $selected = 2 then I want to export the 3th line / [2] from the array to $selectedhash. In this case $selectedhash would be a98b3a8f093d0160614d28f541fb.

What is the quickest and safest way to do this way to do this in php?

Upvotes: 0

Views: 65

Answers (2)

cornelb
cornelb

Reputation: 6066

This also removes target="btcad"

$selectedhash = explode('" ', $myArray[0][$selected]);
$selectedhash = str_replace('"', '', $selectedhash[0]);

Upvotes: 0

darthmaim
darthmaim

Reputation: 5148

You should look up tutorials on basic php, just access your array with a normal index.

$selectedhash = $yourArray[0][ $selected ];

Upvotes: 3

Related Questions