Oihana PHP

prepare.php

Table of Contents

Functions

prepare()  : array<int|string, mixed>
Prepares an array according to the given options: - REDUCE : filter/compress values - BEFORE : prepend keys - AFTER : append keys - FIRST_KEYS + SORT : reorder keys

Functions

prepare()

Prepares an array according to the given options: - REDUCE : filter/compress values - BEFORE : prepend keys - AFTER : append keys - FIRST_KEYS + SORT : reorder keys

prepare(array<int|string, mixed> $array[, array<string, mixed> $options = [] ]) : array<int|string, mixed>

This is typically used before serializing arrays for JSON output.

Parameters
$array : array<int|string, mixed>

The input array.

$options : array<string, mixed> = []

Options for transformation:

  • 'reduce' => bool|array|callable
  • 'before' => array
  • 'after' => array
  • 'first_keys' => array
  • 'sort' => bool
Tags
example
use function oihana\core\arrays\prepare;
use oihana\core\options\ArrayOption;

$result = prepare( [ 'b' => 2, 'a' => 1 ] ,
[
    ArrayOption::FIRST_KEYS => [ 'a' ] ,
    ArrayOption::SORT       => true ,
]);
// [ 'a' => 1, 'b' => 2 ]
author

Marc Alcaraz (ekameleon)

since
1.0.8
Return values
array<int|string, mixed>

The transformed array.

On this page

Search results