{"id":20247846,"url":"https://github.com/northern/php-common","last_synced_at":"2025-04-10T22:24:02.010Z","repository":{"id":14733895,"uuid":"17454733","full_name":"northern/PHP-Common","owner":"northern","description":"PHP Common is a PHP library containing a set of common functionality.","archived":false,"fork":false,"pushed_at":"2018-05-30T20:02:09.000Z","size":86,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T19:21:56.764Z","etag":null,"topics":["php","php-library"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/northern.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-05T20:47:11.000Z","updated_at":"2023-11-16T19:37:35.000Z","dependencies_parsed_at":"2022-08-31T13:20:43.391Z","dependency_job_id":null,"html_url":"https://github.com/northern/PHP-Common","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/northern%2FPHP-Common","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/northern%2FPHP-Common/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/northern%2FPHP-Common/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/northern%2FPHP-Common/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/northern","download_url":"https://codeload.github.com/northern/PHP-Common/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248307245,"owners_count":21081812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php-library"],"created_at":"2024-11-14T09:43:39.896Z","updated_at":"2025-04-10T22:24:01.991Z","avatar_url":"https://github.com/northern.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP Common\n\n[![Build Status](https://travis-ci.org/northern/PHP-Common.png?branch=dev-master)](https://travis-ci.org/northern/PHP-Common)\n\nPHP Common is a PHP library containing a set of common functionality.\n\nTo run tests use:\n\n    composer install -v\n\n    vendor/bin/phpunit\n\nFind PHP Common on [Packagist](https://packagist.org/packages/northern/common):\n\n## ArrayUtil\n\nTo use `ArrayUtil` you need to import it.\n```PHP\nuse Northern\\Common\\Util\\ArrayUtil as Arr;\n```\n### get\n\nTo get a value from an array use `get`:\n```PHP\n$a = array(\n   'foo' =\u003e 'bar'\n);\n\n$value = Arr::get( $a, 'foo' );\n\n// $value == 'bar'\n```\nYou can specify a default value in case the key you're trying to retrieve doesn't exists:\n```PHP\n$value = Arr::get( $a, 'baz', NULL );\n\n// $value == NULL\n```\nTo get a nested value from an array you can specify a path:\n```PHP\n$a = array(\n   'foo' =\u003e array(\n      'bar' =\u003e array(\n         'baz' =\u003e 123\n      )\n   )\n);\n\n$value = Arr::get( $a, 'foo.bar.baz' );\n\n// $value == 123\n```    \nIf required, you can use an alternate delimiter:\n```PHP\n$value = Arr::getPath( $a, 'foo/bar/baz', NULL, '/' );\n\n// $value == 123\n```\n### set\n\nTo set a value or nested value use the `set` method:\n```PHP\n$a = array();\n\nArr::set( $a, 'foo.bar.baz', 123 );\n\n// $a = array( 'foo' =\u003e array( 'bar' =\u003e array( 'baz' =\u003e 123 ) ) );\n```    \nIf the key or path not already exist, it will be created.\n\n### insert\n\nWith `insert` you can create a new value at a path or key, however, the path will only be created if it does not yet exists.\n```PHP\n$a = array();\n\nArr::set( $a, 'foo.bar.baz', 123 );\n\nArr::insert( $a, 'foo.bar.baz', 123 );\n\n// The insert statement does nothing.\n```    \n### delete\n\nIt's also possible to delete a key or path:\n```PHP\nArr::delete( $a, 'foo.bar.baz' );    \n```    \nOr to delete multiple paths or keys at once:\n```PHP\nArr::delete( $a, array('fum', 'foo.bar.baz', 'foo.bar.bob') );\n```\nOr with an alternate delimiter:\n```PHP\nArr::delete( $a, array('fum', 'foo/bar/baz', 'foo/bar/bob'), '/' );\n```\n### exists\n\nTo test if a key or path exists use:\n```PHP\n$value = Arr::exists( $a, 'foo.bar.baz' );\n\n// $value == TRUE\n```    \n### prefix\n\nIf you need to prefix all the values in an array, use the `prefix` method:\n```PHP\n$a = array('1', '2', '3');\n\n$values = Arr::prefix( $a, '$' );\n\n// $values = array('$1', '$2', '$3');\n```\n### postfix\n\nIf you need to postfix all the values in an array, use the `postfix` method:\n```PHP\n$a = array('1', '2', '3');\n\n$values = Arr::postfix( $a, '$' );\n\n// $values = array('1$', '2$', '3$');\n```\n### flatten\n\nSometimes you need to \"flatten\" an array, i.e. glueing the keys and values together with a symbol or character:\n```PHP\n$a = array('param1' =\u003e '123', 'param2' =\u003e 'xyz');\n\n$values = Arr::flatten( $a );\n\n// $values = array('param1=123', 'param2=xyz');\n```    \nOr use a different 'glue' character from the default '=':\n```PHP\n$values = Arr::flatten( $a, '|' );\n\n// $values = array( 'param1|123', 'param2|xyz' );\n```\n### keys\n\nReturns the keys of an array in the same way the `array_keys` function works, however, `keys` allows you to specifiy a prefix:\n```PHP\n$a = array('param1' =\u003e '123', 'param2' =\u003e 'xyz');\n\n$values = Arr::keys( $a, '\u0026' );\n\n// $values = array( '\u0026param1', '\u0026param2' )\n```\n### values\n\nReturns the values of an array in the same way the `array_values` function works, however, `values` allows you to specify a prefix:\n```PHP\n$a = array('param1' =\u003e '123', 'param2' =\u003e 'xyz');\n\n$values = Arr::values( $a, '\u0026' );\n\n// $values = array( '\u0026123', '\u0026xyz' )\n```\n### contains\n\nTests if the values of one array exist in another. E.g:\n```PHP\n$b = Arr::contains( array('A', 'B'), array('A', 'B', 'C') );\n\n// $b = TRUE\n```\nThe above tests if the values of the first array (needle) exist in the second array (haystack), which in the above example is true.\n\n### extract\n\nReturns a value from an array and deletes the key in the array.\n```PHP\n$a = array(\n   'foo' =\u003e 'bar'\n);\n\n$value = Arr::extract( $a, 'foo' );\n\n// $value == 'bar'\n// $a = array()\n```\nThe above example returns the value for `foo` from the array and deletes the `foo` key from the array.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorthern%2Fphp-common","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnorthern%2Fphp-common","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorthern%2Fphp-common/lists"}