Skip to content

Instantly share code, notes, and snippets.

@sorribes22
sorribes22 / xml_parser.php
Created July 16, 2025 06:15
PHP array to XML parser
**
* Convert an array to XML.
*
* Examples:
* 1 - Simple array:
* $data = [
* 'user' => [
* 'name' => 'John',
* 'age' => 30,
* 'address' => [ 'city' => 'New York', 'state' => 'NY' ]
@sorribes22
sorribes22 / change_array_keys.php
Created June 28, 2019 09:55
Change array keys PHP
/**
* @param array $arr Array where keys will be changed
* @param array $keys ['oldKey' => 'newKey']
* @return array Array with changed keys
*/
function change_array_keys(array $arr, array $keys)
{
foreach (array_keys($keys) as $oldKey)
{
if (array_key_exists($oldKey, $arr))
@sorribes22
sorribes22 / Enum.php
Created March 2, 2019 08:05
PHP Enum. Example with Laravel Environment mode
<?php
namespace App\Enums;
use ReflectionClass;
abstract class Enum
{
/**
* Return an associative array with constant name as key and constant value as value.
@sorribes22
sorribes22 / laravelConfigurationDBTest.md
Last active April 9, 2018 06:18
Laravel tests in another DB

More simply. phpunit.xml

<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>

Edit config/database.php file. Add into connections Array new array like this:

'testing' => [
 'driver' =&gt; env('DB_TEST_DRIVER'),