Giter Club home page Giter Club logo

php-array-functions's Introduction

PHP Array Functions

Utility php function can be reused to save development time

Installation

Use composer

Usage

\Asca\array_value_exist($value, array $data)

Checks if value exists in array

Example

$data = ['One', 'Two', 'Three'];
var_dump(\Asca\array_value_exist('One', $data)) // true
var_dump(\Asca\array_value_exist('Five', $data)) // false
\Asca\fast_array_unique(array $data, $reset_keys = false)

Fast Array Unique

Example

$data = ['One', 'Two', 'Three', 'Three'];
var_dump(\Asca\fast_array_unique($data)); // [0 => 'One', 1 => 'Two', 3 => 'Three']
var_dump(\Asca\fast_array_unique($data, true)); // [0 => 'One', 1 => 'Two', 2 => 'Three']
\Asca\value_by_key_path(array $data, $path)

Retrieve a value from multi-dimensional array by key path

Example

$data = [
    'employees' => [
        'junior' => [
            'name' => 'John',
            'years' => 1
        ],
        'intermediate' => [
            'name' => 'Sara',
            'years' => 2,
        ],
        'senior' => [
            'name' => 'Ahmed',
            'years' => 5
        ]
    ]
];

var_dump()\Asca\value_by_key_path($data, 'employees/junior/name'); // John
\Asca\array_diff_both(array $array1, array $array2)

Get all elements from both arrays

Example

$array1 = ['One', 'Two', 'Three', 'Four', 'Five'];
$array2 = ['Two', 'Four', 'Six', 'Eight', 'Ten'];
\Asca\array_diff_both($array1, $array2); //['One', 'Three', 'Five', 'Six', 'Eight', 'Ten']
\Asca\array_to_xml(array $array, $rootNode = 'root')

Converts array to xml

Example

$array = [
    'persons' => [
        'person1' => [
            'name' => 'John Doe',
            'job' => 'Web Developer',
            'years' => 5
        ]
    ]
];

echo \Asca\array_to_xml($array); 
output:
<root>
    <persons>
        <person1>
            <name>John Doe</name>
            <job>Web Developer</job>
            <years>5</years>
        </person1>
    </persons>
</root>

\Asca\array_to_json(array $array, $option = JSON_FORCE_OBJECT)

This is json_encode($array); function

\Asca\array_to_yaml(array $array)

This is yaml_emit($array); function

php-array-functions's People

Contributors

alaa-almaliki avatar

Watchers

 avatar  avatar

php-array-functions's Issues

new idea

Hi :)
Learning your code, I have a new idea, I also wrote a package on the array, can not combine the two packages together!The address of my bag:

composer require nancheng/pfinal-array

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.