{"id":26871254,"url":"https://github.com/codeadamca/php-functions","last_synced_at":"2025-08-26T06:38:02.781Z","repository":{"id":46326279,"uuid":"302436446","full_name":"codeadamca/php-functions","owner":"codeadamca","description":"A basic example of using pre-defined and user-defined PHP functions. ","archived":false,"fork":false,"pushed_at":"2025-01-26T21:40:44.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-11T09:32:03.321Z","etag":null,"topics":["functions","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-08T19:02:53.000Z","updated_at":"2025-01-26T21:40:47.000Z","dependencies_parsed_at":"2024-02-24T19:24:22.659Z","dependency_job_id":"ee2205b4-0f20-4171-8125-36c5b0ecdb56","html_url":"https://github.com/codeadamca/php-functions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codeadamca/php-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/php-functions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272186211,"owners_count":24888333,"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-08-26T02:00:07.904Z","response_time":60,"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":["functions","learning-code","php"],"created_at":"2025-03-31T07:18:54.591Z","updated_at":"2025-08-26T06:38:02.766Z","avatar_url":"https://github.com/codeadamca.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Basic Introduction to JavaScript and Functions\n\nA basic example of using user-defined PHP functions.\n\nThis tutorial will review how to use a series of user-defined functions for format data from a PHP array. \n\n## The End Goal\n\nThe `functions.php` file includes an array with data for three programming books. The array closely resembles data from a MySQL database. \n\nSimilar to the arrays, if, and loops examples, your code needs to output the three values. However, this time it will use some user-defined functions to ensure the prices are formatted properly and display the rating as stars instead of a plain number.\n\n## Steps\n\n1. Open up a new file and name it `functions.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\u003ePHP Functions\u003c/title\u003e \n      \u003c/head\u003e\n      \u003cbody\u003e\n          \n        \u003ch1\u003ePHP Functions\u003c/h1\u003e \n      \n        \u003cp\u003eUse PHP echo, if statements, loops, and functions to output all three books.\u003c/p\u003e\n      \n        \u003c?php\n      \n        // **************************************************\n        // Do not edit this code\n      \n        // Define a multi dimensional array to store all of the books\n        $books = array (\n          0 =\u003e array (\n            'name' =\u003e 'JavaScript and JQuery: Interactive Front-End Web Development',\n            'url' =\u003e'https://www.chapters.indigo.ca/en-ca/books/javascript-and-jquery-interactive-front/9781118531648-item.html',\n            'image' =\u003e 'javascript-jquery.jpg',\n            'description' =\u003e 'Learn JavaScript and jQuery a nicer way.',\n            'rating' =\u003e 4,\n            'price' =\u003e '44.90',\n            'sale' =\u003e '39.90' ),\n          1 =\u003e array ( \n            'name' =\u003e 'Php For The Web: Visual Quickstart Guide',\n            'url' =\u003e'https://www.chapters.indigo.ca/en-ca/books/php-for-the-web-visual/9780134291253-item.html',\n            'image' =\u003e 'php-web.jpg',\n            'description' =\u003e 'Learn PHP programming the quick and easy way!',\n            'rating' =\u003e 3,\n            'price' =\u003e '55.99',\n            'sale' =\u003e '' ),\n          2 =\u003e array (\n            'name' =\u003e 'Beginning Node.js',\n            'url' =\u003e'https://www.chapters.indigo.ca/en-ca/books/beginning-node-js/9781484201886-item.html',\n            'image' =\u003e 'beginning-nodejs.jpg',\n            'description' =\u003e 'A step-by-step guide to learning how to develope a Node.js application.',\n            'rating' =\u003e 5,\n            'price' =\u003e '65.90',\n            'sale' =\u003e '58.90' ),\n          );\n      \n        // **************************************************\n      \n        // Loop through the array and display the link information\n        foreach ($books as $book)\n        {\n      \n          echo '\u003ch2\u003e'.$book['name'].'\u003c/h2\u003e';\n          echo '\u003chr\u003e';\n      \n        }\n      \n        // Use the print_r function to view the contents of the array\n        echo '\u003cpre\u003e';\n        print_r ($books);\n        echo '\u003c/pre\u003e';\n      \n        ?\u003e\n          \n      \u003c/body\u003e\n      \u003c/html\u003e\n      ```\n      \n\u003e [!Note]\n\u003e Do not edit the code between the stars. \n\n3. Before the `doctype` tag create two functions. The first will accept one numeric paraemter and format it as a number using the format $.00.00. The second function will convert a rating t a series of visual start using HTML special chacaters. For example 3/5 would display \u0026#9733;\u0026#9733;\u0026#9733;\u0026#9734;\u0026#9734;.\n\n4. In the `body` section add code that will display the three sets of book information using loops and the two functions defined in the previous step.\n\n\u003e [!Note]\n\u003e Add each value from the arrays one at a time. Test your PHP after each new line of PHP. \n\n\u003e [More information on PHP for loops](https://www.php.net/manual/en/functions.user-defined.php)\n\n\u003e Full tutorial URL:  \n\u003e https://codeadam.ca/learning/php-functions.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-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Fphp-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fphp-functions/lists"}