TwistPHP Documentation

arrayReindex

File path: dist/twist/Core/Models/Tools.model.php
Namespace: Twist\Core\Models
Extends:

arrayReindexRe-index an array of data, provide the key field to be used to re-index the array. The key must exists with a value within the array.
Example of original data:
array(
0 => array('id' => 1, 'name' => 'Home', 'slug' => 'home'),
1 => array('id' => 2, 'name' => 'About', 'slug' => 'about'),
2 => array('id' => 3, 'name' => 'Contact', 'slug' => 'contact'),
)
Example of data after being re-indexed by the key 'slug':
array(
'home' => array('id' => 1, 'name' => 'Home', 'slug' => 'home'),
'about' => array('id' => 2, 'name' => 'About', 'slug' => 'about'),
'contact' => array('id' => 3, 'name' => 'Contact', 'slug' => 'contact'),
)

Parameters

Name Type Description
$arrDataarrayn/a
$strKeyFieldstringn/a
[$blGroup = false]booleann/a

Return Values

void — No return information has been documented for this function.

Example

<?php
//Set the variables for the example
$arrData = array(=> 'foo'=> 'bar');
$strKeyField 'foo';
$blGroup false;

//Call the function arrayReindex with the example vars
$resTools = new \Twist\Core\Models\Tools();
$resTools -> arrayReindex($arrData$strKeyField$blGroup);