opensrs\Ops::_is_assoc PHP Метод

_is_assoc() публичный Метод

Determines if an array is associative or not, since PHP doesn't really distinguish between the two, but Perl/OPS does.
public _is_assoc ( &$array ) : boolean
Результат boolean true if the array is associative
    public function _is_assoc(&$array)
    {
        /*
         * Empty array should default to associative
         * SRS was having issues with empty attribute arrays
         */
        if (empty($array)) {
            return true;
        }
        if (is_array($array)) {
            foreach ($array as $k => $v) {
                if (!is_int($k)) {
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * Should return true for associative, and false for plain.
  */
 public function testIsAssoc()
 {
     $ops = new Ops();
     $no = array(1, 2, 3, 4);
     $yes = array('this' => 'is', 'associative');
     $this->assertFalse($ops->_is_assoc($no));
     $this->assertTrue($ops->_is_assoc($yes));
 }