waUtils

Various helpers

Contents...

Methods

public static function getFieldValues (array $array, $field, $index_key = null)

Extracts the values of a field from array items, associative sub-arrays or objects.

Parameters

Example

$array = array(
	111 => array(
		'id' => 1,
		'name' => 'one',
	),
	222 => array(
		'id' => 2,
		'name' => 'two',
	),
	333 => array(
		'id' => 3,
		'name' => 'three',
	),
);
waUtils::getFieldValues($array, 'name', 'id');
waUtils::getFieldValues($array, 'name', true);
waUtils::getFieldValues($array, 'name', null);

Result

//key is 'id'
array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
);

//true
array(
    111 => 'one',
    222 => 'two',
    333 => 'three',
);

//null
array(
    0 => 'one',
    1 => 'two',
    2 => 'three',
);

public static function varExportToFile ($var, $file, $export = true)

Saves a variable value to a configuration file.

Parameters

Example

//array
$array_var = array(
    'id' => 'some',
    'url' => '/test/',
);
$file = wa()->getConfig()->getConfigPath('plugins/test/config_array.php');
waUtils::varExportToFile($var, $file);

//scalar value
$scalar_var = 1528117809;
$file = wa()->getConfig()->getConfigPath('plugins/test/config_scalar.php');
waUtils::varExportToFile($scalar_var, $file, false);