0

I have the array (the tx array specifcally) below and only want the last one in the array (in this case, 32).

How can this be done? Also, is it possible to add the #s in the array?

For example: 1+2+3...+31+32?

Thanks to anyone that offers help.

Array
(
    [hash] => f52ba5e38ad3a86f54d901fafdb149cbcc190da45783fcdf3099ca272c452289
    [confirmations] => 1
    [size] => 10111
    [height] => 457209
    [version] => 2
    [merkleroot] => 760639a16ade9568c84c3b6ef830b88bc744cb0dc7a35875553852d478f0a4df
    [tx] => Array
        (
            [0] => 4340529c70443dbc9c476b65201307a232ea9aca80d9bcb231d5d302acc2997a
            [1] => cde0d2a5311a981e82dbd8b856a64659f953fbb050246f21beb90cc6595f1ff4
            [2] => 8c01dc9ac687a8ca6e51faf1f882c1ec523046d74a9587500751508b5a6be83d
            [3] => d9777b6ace68484dc723a7e892da6ead5b32d4f1d9ef236a27f76d77500de144
            [4] => 9c4895e4921600d1fbf998115b352254cea94efa9791d3c32be139a6bc2d733a
            [5] => f47314ae4cd118c2b824562f29874209f9cfbd47735bf10f92adfe6cd6a273f8
            [6] => 53b6c6efcdfb0ed13a39d6602f9a1e1e577fbfb30067b839aa779492b8ec16bc
            [7] => f52877a1929ba516261b0cb21603fa30e815ad0b1122f9ec07ce25d9a1c84b0a
            [8] => 615851304a629f490e8fca80be73e6e4eb42e31080fb0827b7387ea97a7d57a8
            [9] => 1df62c690f898cb2328f9a6de25b74f62c8c03ef401ff5e45a7837360302873a
            [10] => e0c787691988d4424e5ae5f9a185a9fbd810b27fd32428041f69f2012155ebe5
            [11] => b20568aeaaffa1beec8b1bc0d4acbbf36a06f1d01093af98e539fcf7a42a67cc
            [12] => 84504f0f3cb0b01b33388639a29b113e8bee467823062f916910d0f6675a2ff3
            [13] => 8af937c341c652a6c9d4cd7e99cf5bb0ac80d0259f02831dc761f5c6f04c0176
            [14] => 3e4e1195900cd9dc238b31784cb366cfb3a9c24e52dfda4eadbc0483f73a5430
            [15] => 1301c674da30547039da4a5cb252576d421d4546acadbcbe08e4cbe72ef9fb41
            [16] => b0564d650cc2c041204122396ffd3fc69b6ea4d7338a9a68f3bf7d8ca8dab319
            [17] => 7861d486982df4ecfd72916663fde4facabfbfbe8606e2f92924233090d5fe51
            [18] => 6e447ebcd20e4dc0e939a33612dc08f5f17bbccdfaa8eaddb52e81e2a7a19af8
            [19] => 7a473f7c7829b3fc0423ed1f3be2dd5f3bc875adce440badd9191206a3135c4e
            [20] => d15c965a52c038b5df3295719072a7ff1820f62f569ca7b393f9537ea98c34af
            [21] => a954bb3ee5923592f150640e4b0aa9c8e75f218412c0856ede4df8885156c41f
            [22] => d6e90a235a5293a7d1655ca2a26871b8e1ff19ffa3d48bd8ebac785b55faa996
            [23] => 5f2c7854b13aa129d147fa095f8b5df4b68000322d37531703a40c1fbd42e467
            [24] => 00299a2efa03dee409650d267f873167afd84b52978d34d256cd3d91efdbecc7
            [25] => 1e136bf8ed16cbeca589e265d86db4ca2abc17207ebe871ef63042c8054a912e
            [26] => 8419ed271faa0fd56d8d37fdd4ba97b2b694a5faaaf6027a5f054f1954bad5ec
            [27] => d7c0246d271a877453f88e0ff5146110d9dc6e650e647d969e9cca7cfe330e7e
            [28] => 591ea2baa8441a0fff5cd86e19730c828fcb259c22379c10e5841e17308f41ec
            [29] => 7a6f9baa6d5a312ec0aeca576948787ec2cf214f6587e970a05f9d410144179f
            [30] => 1c45cde908c7cb6479cab71709f7022540386b5b32765b149cae892d8dc0430f
            [31] => 612e16a6d56aba216c582b71f4942b9f8c5aa3b58fc9f9ce06c8a59006b52bb8
            [32] => 451826b51c3f95a968bde0e79ba526e251c22953dd84b8248cc83c679e360182
        )

    [time] => 1384044294
    [nonce] => 224330496
    [bits] => 1b3ade18
    [difficulty] => 1113.26182029
    [previousblockhash] => 3fec0492c75946e4bcf8b5ddd4cb2ca667c5b892df5bf0df1f68de2d9c7ff366
)
1
  • yeah, and also $arr["#s"] = (count($arr['tx']) - 1)*count($arr['tx']) / 2; Commented Nov 10, 2013 at 0:54

3 Answers 3

4

Test with end of PHP function

end() advances array's internal pointer to the last element, and returns its value.

$fruits = array('apple', 'banana', 'cranberry');
echo end($fruits); // cranberry

UPADATE

$data = array('hash' => 'f52ba5e38ad3a86f54d901fafdb149cbcc190da45783fcdf3099ca272c452289',
'confirmations' => 1,
'size' => 10111,
'height' => '457209',
'version' => 2,
'merkleroot' => '760639a16ade9568c84c3b6ef830b88bc744cb0dc7a35875553852d478f0a4df',
'tx' => array ('4340529c70443dbc9c476b65201307a232ea9aca80d9bcb231d5d302acc2997a','cde0d2a5311a981e82dbd8b856a64659f953fbb050246f21beb90cc6595f1ff4', '8c01dc9ac687a8ca6e51faf1f882c1ec523046d74a9587500751508b5a6be83d')
);

echo key( array_slice( $data['tx'], -1, 1, TRUE ) );

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

5 Comments

I tried it and I need the number though not the string associated with it. Would that function somehow work to get me the number?
$test_array = array(array(tx => array(1,2,3,4,5,6,7))); echo end($test_array[0]['tx']);
What i'm saying is I need the number not the contents after =>
@user2975210 Use the keys: end(array_keys($your_array))
$data = array('hash' => 'f52ba5e38ad3a86f54d901fafdb149cbcc190da45783fcdf3099ca272c452289', 'confirmations' => 1, 'size' => 10111, 'height' => '457209', 'version' => 2, 'merkleroot' => '760639a16ade9568c84c3b6ef830b88bc744cb0dc7a35875553852d478f0a4df', 'tx' => array ('4340529c70443dbc9c476b65201307a232ea9aca80d9bcb231d5d302acc2997a','cde0d2a5311a981e82dbd8b856a64659f953fbb050246f21beb90cc6595f1ff4', '8c01dc9ac687a8ca6e51faf1f882c1ec523046d74a9587500751508b5a6be83d') ); //end($data['tx']); echo key( array_slice( $data['tx'], -1, 1, TRUE ) );
0

$array['tx']Use end

Say that array you have is $array.

$tx_array = $array['tx']

The last entry is

$last = end($tx_array);

last key

$lastkey = end(array_keys($tx_array));

1 Comment

That prints the string, I need the number.
0
end($array['tx']);
print key($array['tx']); # 32

Even better:

print end(array_keys($array['tx'])); # 32

If the indexes are continuous:

print count($array['tx']) - 1; # 32

To set $array['#s']:

$array['#s'] = array_sum(array_keys($array['tx']));

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.