File path: dist/twist/Core/Models/Tools.model.php
Namespace: Twist\Core\Models
arrayReindex
— Re-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'),
)
Name | Description |
---|---|
$arrData | n/a |
$strKeyField | n/a |
[$blGroup = false] | n/a |
void — No return information has been documented for this function.
<?php
//Set the variables for the example
$arrData = array(0 => 'foo', 1 => 'bar');
$strKeyField = 'foo';
$blGroup = false;
//Call the function arrayReindex with the example vars
$resTools = new \Twist\Core\Models\Tools();
$resTools -> arrayReindex($arrData, $strKeyField, $blGroup);