{"id":26871278,"url":"https://github.com/codeadamca/php-arrays","last_synced_at":"2025-09-15T12:17:35.936Z","repository":{"id":115328370,"uuid":"291543468","full_name":"codeadamca/php-arrays","owner":"codeadamca","description":"A basic example of using PHP arrays.","archived":false,"fork":false,"pushed_at":"2025-01-26T21:34:44.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T07:18:55.451Z","etag":null,"topics":["arrays","learning-code","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeadamca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-08-30T20:06:32.000Z","updated_at":"2025-01-26T21:34:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"ae501ed0-c127-49b4-8e99-4c0fc3237396","html_url":"https://github.com/codeadamca/php-arrays","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codeadamca/php-arrays","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-arrays","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-arrays/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-arrays/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-arrays/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/php-arrays/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-arrays/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275254777,"owners_count":25432331,"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","status":"online","status_checked_at":"2025-09-15T02:00:09.272Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["arrays","learning-code","php"],"created_at":"2025-03-31T07:18:57.915Z","updated_at":"2025-09-15T12:17:35.891Z","avatar_url":"https://github.com/codeadamca.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Basic Introduction to PHP and Arrays\n\nA basic example of using PHP arrays.\n\nThis tutorial will review how to define and use PHP arrays when creating HTML output. Here is a basic sample of using an array and the `echo` command to create a personalized hello mesage.\n\n```php\n\u003c?php \n\n$person['first'] = 'Jane';\n$person['last'] = 'Doe';\necho '\u003cp\u003eHello '.$person['first'].' '.$person['last'].'!\u003c/p\u003e';\n\n?\u003e\n```\n\nArrays are a special type of variable that can be used to store more than one piece of data. Each piece of data is assigned a key. The example above includes one array named `$person` and two keys `first` and `last`. Arays are often used to store a list of data:\n\n```php\n\u003c?php\n\n$languages = array( 'PHP', 'HTML', 'JavaScript', 'CSS' );\n\n?\u003e\n```\n\nOr a group of information like an individuals profile:\n\n```php\n\u003c?php \n\n$person['first'] = 'Jane';\n$person['last'] = 'Doe';\n$person['email'] = 'jane.doe@email.com';\n$person['age'] = 30;\n\n?\u003e\n```\n\nThere are some rules when naming your arrays and keys:\n\n- Array names must follow the same rules as variable names.\n- Unlike variables names, array keys can start with numbers or be numeric.\n- Array keys can use any alpha-numeric characters and underscores.\n- Array keys are case sensitive.\n\n## The End Goal\n\nThe goal of this series of lessons is to become comfortable with retrieveing data from a database and displaying the data in a web page. When working with database data the process roughly follows these steps:\n\n1. Fetch data from the database.\n2. Create a loop to iterate through the retrieved data.\n3. Use if statements to check which data is ready for output.\n4. Put the data into a series of variables and/or arays.\n5. Use `echo` to output the variables and format them with HTML. \n\nIn this lesson we're going to focus on the last step, outputting data using HTML, variables, and the `echo` statement. This time the data will be placed in an array.\n\n## Steps\n\n1. Open up a new file and name it arrays.php.\n2. Add the following code to the new PHP file:\n    \n    ```php\n    \u003c!doctype html\u003e\n    \u003chtml\u003e\n    \u003chead\u003e\n        \u003ctitle\u003eLinks and Arrays\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \n        \u003ch1\u003eLinks and Arrays\u003c/h1\u003e\n        \n        \u003cp\u003eUse PHP echo and arrays to output the following link information:\u003c/p\u003e\n            \n        \u003chr\u003e\n        \n        \u003c?php\n        \n        $link['name'] = 'Codecademy';\n        $link['url'] = 'https://www.codecademy.com/';\n        $link['image'] = 'codecademy.png';\n        $link['description'] = 'Learn to code interactively, for free.';\n        \n        ?\u003e\n            \n    \u003c/body\u003e\n    \u003c/html\u003e\n    ```\n\n3. After the array is defined use a series of `echo` statements to display the content. For example outputting the `$link['name']` might look like this:\n    \n    ```php\n    \u003c?php\n    \n    echo '\u003ch1\u003e'.$link['name'].'\u003c/h1\u003e';\n    \n    ?\u003e\n    ```\n\n\u003e [!Note]\n\u003e Add each value from the array one at a time. Test your PHP after each new line of PHP. \n\n\u003e [More information on PHP arrays](https://www.php.net/manual/en/language.types.array.php)\n\n\u003e Full tutorial URL:  \n\u003e https://codeadam.ca/learning/php-arrays.html\n\n***\n\n## Repo Resources\n\n* [Visual Studio Code](https://code.visualstudio.com/) or [Brackets](http://brackets.io/) (or any code editor)\n* [Filezilla](https://filezilla-project.org/) (or any FTP program)\n\n\u003cbr\u003e\n\u003ca href=\"https://codeadam.ca\"\u003e\n\u003cimg src=\"https://cdn.codeadam.ca/images@1.0.0/codeadam-logo-coloured-horizontal.png\" width=\"200\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fphp-arrays","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Fphp-arrays","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fphp-arrays/lists"}