Wiki

Clone wiki

php-utils / Home

bytefreaks php-utils

This Library contains some nice PHP functions for daily work.

  • array array_strip ( array $array )

Traverse recursive through given array and applies stripslashes().

  • array array_merge_recursiv\e_simple ( array $a, array $b )

Merges array $b recursive into array $a.

  • array array_call_method ( array $array, string $methodname [, mixed $... ] )

Iterates over the given $array and calls the given $methodname on every item passing additionals parameters as parameters to the method. Every return value will be collected and returned as array.

  • array array_call_function ( array $array, string $functions )

Iterates over the given $array and calls the given $function on every item passing the item itself to the function. Every return value will be collected and returned as array.

Multiple functions can be used by seperating the functionnames by comma (,).

$functions doesn't yet support anonymous functions!

  • array array_create_hash ( array $array, string $fieldname [, $duplicate_as_array = false])

Creates a hashtable using a key from the values of given array without changing the value. If $duplicate_as_array is set to true, all items with the same key will be collected as array.

#!php
  $records = array(
    array("id" => 23,"name"=>"john"),
    array("id" => 42,"name"=>"miller")
  );
  $recordsById = array_create_hash($records,"id");
  // $recordsById should now contain: $recordsById = array(23 => array("id" => 23, "name" => "john"), 42 => array("id" => 42, "name" => "miller"))
  • array array_create_simple_hash ( array $array, string $key_fieldname , string $value_fieldname)

Creates a hashtable using a key identified by $key_fieldname and a value identified by $valu\e_fieldname from the values of given array.

#!php
  $records = array(
    array("id" => 23,"name"=>"john"),
    array("id" => 42,"name"=>"miller")
  );
  $namesById = array_create_simple_hash($records,"id","name");
  // $namesById should now contain: $namesById = array(23 => "john", 42 => "miller")
  • array array_group ( array $array, string|string[] $fieldname )

Creates a new array grouping all records in $array by the values of a given $fieldname.

$fieldname can be an array of fieldnames. In the resulting array the values of all fields will be concated with "_".

  • array array_set_value ( array $array, string $fieldname, mixed $value )

Sets $fieldname to $value in every item in $array.

  • mixed array_get_by_keypath ( array $array, string $keypath )

Returns the value in the given $array identified by $keypath. $keypath is a string with all pathcomponents seperated by a dot (.).

#!php
  $records = array(
    array("id" => 23,"name"=>"john"),
    array("id" => 42,"name"=>"miller")
  );
  $name = array_get_by_keypath($records, "1.name");
  // $name = "miller"
  • array_set_by_keypath ( array $array, string $keypath, mixed $value )

Sets a $value in $array at position identified by $keypath. See array_get_by_keypath().

  • array array_sort_by_column ( array $array, string $column [[,$dir = SORT_ASC], $type = SORT_REGULAR] )

Executed an array_multiort() on the given $array sorting by the specified $column.

  • bool str_begins_with ( string $string, string $needle [,$casesensitive = false] )

Checks wether a $string begins with a specific $needle.

  • bool str_ends_with ( string $string, string $needle [,$casesensitive = false] )

Checks wether a $string ends with a specific $needle.

  • debug_break ([*$...])

Exits the current script by printing a backtrace and the current code position. If any arguments are passed to this function they will be dumped with var_dump().

Updated