PHP arrays are different from py objects, which are:
- PHP keys can be integer or string (associative),
- When a value is added to the array, a digital key is automatically assigned before the key / value pair is added to the array. The assigned associated key has an integer value equal to the maximum value from the internal numeric iterator pointers of the array plus 1,
- Numeric integer keys in a string are displayed as integers,
- The insertion order into the array is preserved. key / value pairs are repeated in accordance with the key entry order. We can use Python's Orderedict to follow,
- PHP
array[] = 5 translated into Python array.append(5) or array[None] = 5 , - The keys of the iterator indexer are processed through the built-in PHP functions or passed by reference, with a copy to the write policy.
I would like to provide a plugin for my newly released pyx.php Python module. There is a Python array class in the module that emulates a PHP array. Our Python emulation of a PHP array uses an instance variable OrderedDict, where array._obj is OrderedDic to store all elements of the array and track their insert orders using a special instance of the pointer variable. Try:
$ git clone https://github.com/wordpy/pyx/ $ python
zip() works for an array with different len !!!
>>> for i,j in zip( array(1,2,3,4), array(11,22,33) ): ... print(i,j) 1 11 2 22 3 33 >>> for i,j in zip( array(1,2), array(11,22,33) ): ... print(i,j) 1 11 2 22
array() in the pyx.php module Cython offers almost everything that PHP offers array (), as well as many other methods. See https://wordpy.com/pyx/php/ .
pyx.php is currently only available for Python 3.x, which runs on a 64-bit version of Linux. Python 2.x, Mac, or other platforms can be compiled when there are many requests.
source share