PHP Classes

File: src/Generics/Util/Arrays.php

Recommend this page to a friend!
  Classes of Maik Greubel   PHP Generics   src/Generics/Util/Arrays.php   Download  
File: src/Generics/Util/Arrays.php
Role: Class source
Content type: text/plain
Description: Arrays support utilities
Class: PHP Generics
Framework for accessing streams, sockets and logs
Author: By
Last change: Update of src/Generics/Util/Arrays.php
Date: 7 months ago
Size: 1,009 bytes
 

Contents

Class file image Download
<?php

/**
 * This file is part of the PHP Generics package.
 *
 * @package Generics
 */
namespace Generics\Util;

use
ArrayObject;

/**
 * This class provides some array utility functions
 *
 * @author Maik Greubel <greubel@nkey.de>
 *
 */
class Arrays
{

   
/**
     * Create an empty array containing a specific number of elements
     *
     * @param int $numElements
     * The number of elements in Array
     * @return array
     */
   
public static function createEmptyArray($numElements): ArrayObject
   
{
        return new
ArrayObject(array_fill(0, $numElements, null));
    }

   
/**
     * Check whether a key exists in array and corresponding value is not empty
     *
     * @param array $array
     * @param mixed $element
     * @return bool
     */
   
public static function hasElement($array, $element): bool
   
{
        if (!
is_array($array)) {
            return
false;
        }
       
        return isset(
$array[$element]) && strlen($array[$element]) > 0;
    }
}