{"id":26871280,"url":"https://github.com/codeadamca/php-variables","last_synced_at":"2025-10-24T20:13:08.429Z","repository":{"id":115328462,"uuid":"264990750","full_name":"codeadamca/php-variables","owner":"codeadamca","description":"A basic example of using PHP variables. ","archived":false,"fork":false,"pushed_at":"2025-01-26T21:34:30.000Z","size":277,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T22:25:30.840Z","etag":null,"topics":["learning-code","php","variables"],"latest_commit_sha":null,"homepage":"https://professoradamthomas.com/learning/php/variables.html","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-05-18T16:02:46.000Z","updated_at":"2025-01-26T21:34:33.000Z","dependencies_parsed_at":"2023-08-20T08:46:14.786Z","dependency_job_id":null,"html_url":"https://github.com/codeadamca/php-variables","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fphp-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/php-variables/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429486,"owners_count":20775809,"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":["learning-code","php","variables"],"created_at":"2025-03-31T07:18:58.109Z","updated_at":"2025-10-24T20:13:08.357Z","avatar_url":"https://github.com/codeadamca.png","language":"PHP","readme":"# A Basic Introduction to PHP and Variables\n\nA basic example of using PHP variables.\n\nThis tutorial will review how to define and use PHP variables when creating HTML output. Here is a basic sample of using a variable and the `echo` command to create a personalized hello mesage.\n\n```php\n\u003c?php \n\n$name = 'Jane Doe';\necho '\u003cp\u003eHello '.$name.'!\u003c/p\u003e';\n\n?\u003e\n```\n\nVariables are used to temporary store data and then reference that data later on in your code. For example, a visitor could fill out a contact form, the contact form data is then stored in a series of variables, and then later on could be used to display a personalized message and/or send a personalized email.\n\nThere are some rules when naming your variables:\n\n- Variable names start with the `$` sign\n- Variable names must start with a letter or an underscore\n- Variable names can contain alpha-numeric characters and underscores\n- Variable names 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.\n\n## Steps\n\n1. Open up a new file and name it variables.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 Variables\u003c/title\u003e\n    \u003c/head\u003e\n    \u003cbody\u003e\n        \n        \u003ch1\u003eLinks and Variables\u003c/h1\u003e\n        \n        \u003cp\u003eUse PHP echo and variables to output the following link information:\u003c/p\u003e\n            \n        \u003chr\u003e\n        \n        \u003c?php\n        \n        $linkName = 'Codecademy';\n        $linkURL = 'https://www.codecademy.com/';\n        $linkImage = 'codecademy.png';\n        $linkDescription = 'Learn to code interactively, for free.';\n        \n        ?\u003e\n            \n    \u003c/body\u003e\n    \u003c/html\u003e\n    ```\n\n3. After the variables are defined use a series of `echo` statements to display the content. For example outputting the `$linkname` might look like this:\n    \n    ```php\n    \u003c?php\n    \n    echo '\u003ch1\u003e'.$linkName.'\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 variables](https://www.php.net/manual/en/language.variables.variable.php)\n\n\u003e Full tutorial URL:  \n\u003e https://codeadam.ca/learning/php-variables.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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fphp-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Fphp-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fphp-variables/lists"}