What is this php data structure and what would be the python equivalent?

I am writing a python script but I’m getting ideas from a php implementation. However, I’ve never spent time working on php before. Could someone explain to me this structure:

1. for ($i=0; $i<$invarint_value; $i++) {
2. $array['vin'][$i]['txid'] = swapEndian(substr($data, 0, 64));
3. }

Original php code: link, line 46

I’m trying to create its python version. I’m interested in understanding the data structure in the left-hand side of line 2. Thanks!

Dunno.

No context of the original array.

As posted… not valid code.

As posted… does ‘nothing’ doesnt assign nor echo any content.

The original post has been edited. Consider the right hand side irrelevant. I’m trying to understand the data structure so I can write the python equivalent.

Original php code: link, line 46

ok… well that code actually makes sense/does something.

The second line is assigning a value to the

‘VIN -$i- TAXID’ index in the array.

Seems to be using a function swapEndian() to parse/get this data that is being assigned to the array.

Thank you for your reply. I understand the general purpose; the value of the right-hand side is assigned at the structure of the left-hand side. I’m trying to understand the structure on the left-hand side.

What is the difference between

$array['vin'][$i]['txid']

and

$array['vin'][$i]

What sort of array is it? Why does it have two key indexes but assigns a single value? Is it a multidimensional array? is it something else? I could think of it as a python dictionary but the two key indexes confuse me.

I am trying to get familiar with php syntax.

Oh… I see

Yes… correct… it is a multi-dimensional array. (with a sub-array)

$array['vin'][0]['txid'] = 'xxx'
$array['vin'][1]['txid'] = 'yyy'
$array['vin'][2]['txid'] = 'zzz'

So the difference here is… that the

$array['vin'][$i]

Is just an index/pointer to the TXID value

$array[‘vin’][$i][‘txid’] points to the actual value

There might be other info associated with each ‘VIN’ as well.

$array['vin'][0]['txid']
$array['vin'][0]['owner_name']

$array['vin'][1]['txid']
$array['vin'][1]['owner_name']

So $array[‘vin’][$i] is just what VIN (in an array of VIN’s) that you are looking at. (or assigning values to)

So not only is it an array of VIN’s… but each VIN is an array as well… so you need to then access the data in the VIN (sub) array.

Unfortunately… I know ‘0’ Python… (although I plan on it playing with it soon… as I do Arduino/RaspberryPi projects… and it would probably be easier!) LOL

Hope that helps.

1 Like

Your answer helped a lot. I managed to write the python version, although I believe it’s less efficient compared to this php implementation. I’ll work on it…

Thanks a lot and good luck with python! :smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service