private function serializeArrayOrTable(array $array)
    {
        $assoc = false;
        $index = 0;
        $values = [];

        foreach ($array as $key => $value) {
            // We already know the array is associative, serialize both the key
            // and the value ...
            if ($assoc) {
                $values[] = $this->serializeShortString($key)
                    . $this->serializeField($value);

                // Otherwise, if the key matches the index counter it is sequential,
                // only serialize the value ...
            } elseif ($key === $index++) {
                $values[] = $this->serializeField($value);

                // Otherwise, we've just discovered the array is NOT sequential,
                // Go back through the existing values and add the keys ...
            } else {
                foreach ($values as $k => $v) {
                    $values[$k] = $this->serializeShortString($k) . $v;
                }

                $values[] = $this->serializeShortString($key)
                    . $this->serializeField($value);

                $assoc = true;
            }
        }

        return ($assoc ? 'F' : 'A') . $this->serializeByteArray(
                implode('', $values)
            );
    }
private function serializeArrayOrTable(array $array)
    {
        $assoc = false;
        $index = 0;
        $values = [];

        foreach ($array as $key => $value) {
            // We already know the array is associative, serialize both the key
            // and the value ...
            if ($assoc) {
                $values[] = $this->serializeShortString($key)
                    . $this->serializeField($value);

                // Otherwise, if the key matches the index counter it is sequential,
                // only serialize the value ...
            } elseif ($key === $index++) {
                $values[] = $this->serializeField($value);

                // Otherwise, we've just discovered the array is NOT sequential,
                // Go back through the existing values and add the keys ...
            } else {
                foreach ($values as $k => $v) {
                    $values[$k] = $this->serializeShortString($k) . $v;
                }

                $values[] = $this->serializeShortString($key)
                    . $this->serializeField($value);

                $assoc = true;
            }
        }

        return ($assoc ? 'F' : 'A') . $this->serializeByteArray(
                implode('', $values)
            );
    }
private function serializeArrayOrTable ( array $ array ) { $ assoc = false ; $ index = 0 ; $ values = [ ] ; foreach ( $ array as $ key => $ value ) { // We already know the array is associative, serialize both the key // and the value ... if ( $ assoc ) { $ values [ ] = $ this -> serializeShortString ( $ key ) . $ this -> serializeField ( $ value ) ; // Otherwise, if the key matches the index counter it is sequential, // only serialize the value ... } elseif ( $ key === $ index ++ ) { $ values [ ] = $ this -> serializeField ( $ value ) ; // Otherwise, we've just discovered the array is NOT sequential, // Go back through the existing values and add the keys ... } else { foreach ( $ values as $ k => $ v ) { $ values [ $ k ] = $ this -> serializeShortString ( $ k ) . $ v ; } $ values [ ] = $ this -> serializeShortString ( $ key ) . $ this -> serializeField ( $ value ) ; $ assoc = true ; } } return ( $ assoc ? 'F' : 'A' ) . $ this -> serializeByteArray ( implode ( '' , $ values ) ) ; }
Serialize a PHP array.

If the array contains sequential integer keys, it is serialized as an AMQP
array, otherwise it is serialized as an AMQP table.

@param array $array

@return string The binary serialized table.
@throws \InvalidArgumentException
Serialize a PHP array .