├── .env.example
├── .github
├── CODEOWNERS
├── FUNDING.yml
├── pull_request_template.md
└── workflows
│ ├── checkCode.yml
│ ├── codeql.yml
│ └── markdown-linter.yml
├── .gitignore
├── .htaccess
├── .markdownlint.json
├── .markdownlintignore
├── .mergify.yml
├── .prettierignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── algorithms
├── BackTracking
│ ├── PathFinding
│ │ ├── PathFinding.php
│ │ └── README.md
│ └── README.md
├── README.md
├── Searching
│ ├── Binary
│ │ ├── BinarySearch.php
│ │ └── README.md
│ ├── Jump
│ │ ├── JumpSearch.php
│ │ └── README.md
│ ├── Linear
│ │ ├── LinearSearch.php
│ │ └── README.md
│ ├── README.md
│ └── Ternary
│ │ ├── README.md
│ │ └── TernarySearch.php
├── Sorting
│ ├── BubbleSort
│ │ ├── BubbleSort.php
│ │ └── README.md
│ ├── CountingSort
│ │ ├── CountingSort.php
│ │ └── README.md
│ ├── PopSort
│ │ ├── PopSort.php
│ │ └── README.md
│ ├── README.md
│ └── SelectionSort
│ │ ├── README.md
│ │ └── SelectionSort.php
├── autoload.php
└── run.php
├── assets
├── content
│ ├── algorithms
│ │ ├── Searching
│ │ │ ├── Binary
│ │ │ │ ├── Binary.gif
│ │ │ │ └── Binary.svg
│ │ │ ├── Jump
│ │ │ │ ├── Jump.svg
│ │ │ │ └── jump.gif
│ │ │ ├── Linear
│ │ │ │ ├── Linear.gif
│ │ │ │ └── chart.svg
│ │ │ └── Ternary
│ │ │ │ ├── Ternary.svg
│ │ │ │ └── ternary.png
│ │ └── Sorting
│ │ │ ├── Bubble
│ │ │ ├── BubbleSort.svg
│ │ │ └── diagram.png
│ │ │ ├── CountingSort
│ │ │ └── counting-sort.png
│ │ │ ├── PopSort
│ │ │ ├── popsort1.png
│ │ │ ├── popsort2.png
│ │ │ ├── popsort3.png
│ │ │ ├── popsort4.png
│ │ │ ├── popsort5.png
│ │ │ ├── popsort_finale.png
│ │ │ └── tower_of_hanoi.jpeg
│ │ │ └── SelectionSort
│ │ │ ├── 1.png
│ │ │ ├── 2.png
│ │ │ ├── 3.png
│ │ │ ├── 4.png
│ │ │ ├── 5.png
│ │ │ ├── 6.png
│ │ │ ├── 7.png
│ │ │ ├── 8.png
│ │ │ ├── 9.png
│ │ │ └── selection-sort-flowchart.png
│ ├── basics
│ │ ├── 10_file_handling
│ │ │ └── file_handling.txt
│ │ ├── 12_database_dasar_prosedural
│ │ │ ├── 1_xampp.jpg
│ │ │ ├── 2_phpmyadmin.png
│ │ │ ├── 3_database_jadi.png
│ │ │ ├── 4_table_1.png
│ │ │ ├── 5_table_2.png
│ │ │ ├── 6_table_3.png
│ │ │ ├── 7_insert.png
│ │ │ ├── 8_update.png
│ │ │ └── 9_delete.png
│ │ ├── 14_oop_dasar
│ │ │ ├── 1-prosedural.png
│ │ │ ├── 2-oop.png
│ │ │ ├── object1.png
│ │ │ └── object2.png
│ │ ├── 15_oop_lanjutan
│ │ │ ├── 3_private.gif
│ │ │ └── 3_protected.gif
│ │ ├── 5_perulangan
│ │ │ ├── do_while.png
│ │ │ ├── for_loop.png
│ │ │ └── while.png
│ │ ├── 5_string_manipulation
│ │ │ ├── kutip''.png
│ │ │ ├── kutip2''.png
│ │ │ ├── ltrim.gif
│ │ │ ├── rtrim.gif
│ │ │ ├── slash''.png
│ │ │ ├── stripslashes.png
│ │ │ ├── stripslashes0.png
│ │ │ ├── strpos.gif
│ │ │ ├── substr_count.gif
│ │ │ └── trim.gif
│ │ ├── 7_array_mendalam
│ │ │ ├── array diff __sebelum_diff.svg
│ │ │ ├── array diff __setelah_diff.svg
│ │ │ ├── array pop __sebelum_pop.svg
│ │ │ ├── array pop __setelah_pop.svg
│ │ │ ├── array push __sebelum_push.svg
│ │ │ ├── array push __setelah_push.svg
│ │ │ ├── array shift __sebelum_shift.svg
│ │ │ ├── array shift __setelah_shift.svg
│ │ │ ├── array unshift __sebelum_unshift.svg
│ │ │ ├── array unshift __setelah_unshift.svg
│ │ │ └── memori_array.png
│ │ └── 8_fungsi_dasar
│ │ │ └── comment.png
│ └── cekhere.svg
├── css
│ ├── all.min.css
│ ├── bootstrap.min.css
│ ├── global.css
│ └── markdown-style.css
├── images
│ ├── 14-7-1-360px-Opened_light_switch.jpg
│ ├── 14-7-2-527px-Light_switch_inside_explained.jpg
│ ├── 8.1pouring tea realistic.jpg
│ ├── Webysther_20160423_-_Elephpant.svg.png
│ ├── background-pattern.jpg
│ ├── bellshade-inline.png
│ ├── getting-started.png
│ ├── icon.png
│ ├── logo.png
│ ├── mpdf.png
│ ├── phpicon.png
│ └── phplogo.png
├── js
│ ├── all.min.js
│ ├── bootstrap.bundle.min.js
│ └── markdown.js
└── webfonts
│ ├── Poppins-Regular.ttf
│ ├── Poppins-Regular.woff2
│ ├── fa-brands-400.eot
│ ├── fa-brands-400.svg
│ ├── fa-brands-400.ttf
│ ├── fa-brands-400.woff
│ ├── fa-brands-400.woff2
│ ├── fa-regular-400.eot
│ ├── fa-regular-400.svg
│ ├── fa-regular-400.ttf
│ ├── fa-regular-400.woff
│ ├── fa-regular-400.woff2
│ ├── fa-solid-900.eot
│ ├── fa-solid-900.svg
│ ├── fa-solid-900.ttf
│ ├── fa-solid-900.woff
│ └── fa-solid-900.woff2
├── basics
├── 10_file_handling
│ ├── 1_membaca_file_dan_folder.php
│ ├── 2_create_file_folder.php
│ ├── 3_write_file.php
│ ├── 4_delete_file.php
│ ├── 5_upload_file.php
│ ├── 6_validation_file.php
│ └── README.md
├── 11_cookie_dan_session
│ ├── 1_set_session.php
│ ├── 2_get_session.php
│ ├── 3_update_session.php
│ ├── 4_delete_session.php
│ ├── 5_set_cookie.php
│ ├── 6_update_cookie.php
│ ├── 7_delete_cookie.php
│ └── README.md
├── 12_database_dasar_prosedural
│ ├── 2_connect.php
│ ├── 3_query_delete.php
│ ├── 3_query_insert.php
│ ├── 3_query_update.php
│ ├── 4_mysqli_fetch.php
│ └── README.md
├── 14_oop_dasar
│ ├── 1_prosedural_dan_oop.php
│ ├── 2_class_and_object.php
│ ├── 3_property_and_method.php
│ ├── 4_constructor_destructor.php
│ ├── 4_constructor_destructor2.php
│ ├── 5_property_dan_method_static.php
│ ├── 6_constant_magic_constants.php
│ ├── 6_constant_magic_constants2a.php
│ ├── 6_constant_magic_constants2b.php
│ ├── 6_constant_magic_constants3.php
│ ├── 7_setter_dan_getter.php
│ ├── 7_setter_dan_getter2.php
│ ├── 7_setter_dan_getter3.php
│ ├── 7_setter_dan_getter4.php
│ ├── 7_setter_dan_getter5.php
│ ├── 7_setter_dan_getter6.php
│ ├── 8_method_chaining.php
│ ├── 8_method_chaining2.php
│ ├── 8_method_chaining3.php
│ ├── 8_method_chaining4.php
│ └── README.md
├── 15_oop_lanjutan
│ ├── 1_inheritance_Hewan.php
│ ├── 1_inheritance_Kucing.php
│ ├── 2_object_type.php
│ ├── 3_access_modifier.php
│ ├── 4_overriding_and_final.php
│ └── README.md
├── 1_hello_world
│ ├── 2_hello_world.php
│ ├── 3_php_html.php
│ └── README.md
├── 2_variable_datatype
│ ├── 1_data_type.php
│ ├── 2_variable_in_string.php
│ ├── 3_array.php
│ ├── 4_constant_variable.php
│ └── README.md
├── 3_operator
│ ├── 1_aritmatika_operator.php
│ ├── 2_assignment_operator.php
│ ├── 3_comparison_operator.php
│ ├── 4_logical_operator.php
│ ├── 5_bitwise_operator.php
│ ├── 7_increment_decrement_operator.php
│ ├── 8_string_operator.php
│ ├── 9_array_operator.php
│ ├── README.md
│ ├── null_coalesce.php
│ └── tenary_operator.php
├── 4_conditional_statements
│ ├── 1_if_elseif_else.php
│ ├── 2_switch.php
│ ├── 3_operator_ternary.php
│ ├── 4_ternary_assignment.php
│ ├── 5_ternary_shorthand.php
│ └── README.md
├── 5_perulangan
│ ├── 1_for.php
│ ├── 2_foreach.php
│ ├── 3_while.php
│ ├── 4_do_while.php
│ └── README.md
├── 6_manipulasi_string
│ ├── 1_properti_string.php
│ ├── 2_pemotongan_string.php
│ ├── 3_kapitalisasi_string.php
│ ├── 4_string_array.php
│ ├── 5_escape_dan_formatting.php
│ ├── 6_manipulasi_string.php
│ └── README.md
├── 7_array_mendalam
│ ├── 1_array.php
│ ├── 2_jenis_array.php
│ ├── 3_1_array_multidimensi.php
│ ├── 3_2_implementasi_table_array.php
│ ├── 3_3_array_kedalam_table.php
│ ├── 4_manipulasi_array_array_diff.php
│ ├── 4_manipulasi_array_array_flip.php
│ ├── 4_manipulasi_array_array_keys.php
│ ├── 4_manipulasi_array_array_merge.php
│ ├── 4_manipulasi_array_array_pop.php
│ ├── 4_manipulasi_array_array_push.php
│ ├── 4_manipulasi_array_array_rand.php
│ ├── 4_manipulasi_array_array_reverse.php
│ ├── 4_manipulasi_array_array_shift.php
│ ├── 4_manipulasi_array_array_slice.php
│ ├── 4_manipulasi_array_array_splice.php
│ ├── 4_manipulasi_array_array_unshift.php
│ ├── 4_manipulasi_array_array_values.php
│ ├── 4_manipulasi_array_arsort.php
│ ├── 4_manipulasi_array_asort.php
│ ├── 4_manipulasi_array_count.php
│ ├── 4_manipulasi_array_krsort.php
│ ├── 4_manipulasi_array_ksort.php
│ ├── 4_manipulasi_array_rsort.php
│ ├── 4_manipulasi_array_sizeof_1.php
│ ├── 4_manipulasi_array_sizeof_2.php
│ ├── 4_manipulasi_array_sort.php
│ └── README.md
├── 8_fungsi_dasar
│ ├── 1_Basic_Function.php
│ ├── 2_Parameter_Return.php
│ ├── 3_Scope_Variabel.php
│ ├── 4_Static_Variable.php
│ ├── 5_Closure_Function.php
│ ├── 6_Rekursif_Function.php
│ └── README.md
├── 9_form_handling
│ ├── 1_submit_button.php
│ ├── 2_input_based_text.php
│ ├── 3_select.php
│ ├── 4_datetime.php
│ ├── 5_checkbox.php
│ ├── 6_radio.php
│ ├── 7_file.php
│ ├── 8_multiple_file.php
│ └── README.md
├── README.md
└── backup
│ ├── array
│ ├── array_basic.php
│ └── array_search.php
│ └── loop
│ └── recursive_loop.php
├── composer.json
├── composer.lock
├── config.php
├── index.php
├── package-lock.json
├── package.json
├── phpcs.xml
├── renovate.json
├── router.php
├── tests
├── BackTracking
│ └── PathFindingTest.php
├── Searching
│ ├── BinarySearchTest.php
│ ├── JumpSearchTest.php
│ ├── LinearSearchTest.php
│ └── TernarySearchTest.php
└── Sorting
│ ├── BubbleSortTest.php
│ ├── CountingSortTest.php
│ ├── PopSort.php
│ └── SelectionSortTest.php
└── utilities
├── Kalkulator_sederhana
├── README.md
├── index.php
└── kalkulator_syzkii
│ ├── README.md
│ ├── index.php
│ ├── kalkulator.PNG
│ └── kalkulator_index.php
├── Login_Dan_Logout
├── README.md
└── login_dan_logout
│ ├── README.md
│ ├── login_cek.php
│ ├── login_form_index.php
│ └── logout.php
├── README.md
├── SImple_UnitTest
├── README.md
├── SimpleTest.php
├── WordCount.php
├── composer.json
└── composer.lock
├── datetime
├── README.md
└── datetime_php
│ ├── README.md
│ ├── datetime_basic.php
│ └── datetime_operation.php
├── fpdf
└── README.md
├── mpdf
├── README.md
└── mpdf.php
├── random_password
├── generate.php
└── readme.md
├── reCAPTCHA
├── README.md
└── google_reCAPTCHA
│ ├── README.md
│ ├── captcha.php
│ └── images
│ ├── 0.png
│ ├── 1.png
│ ├── 2.png
│ ├── 3.png
│ └── 4.png
└── simple_curl
├── README.md
├── curl.php
└── prayogaea.php
/.env.example:
--------------------------------------------------------------------------------
1 | BASE_URL=http://localhost/php
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 |
2 | # This is a comment.
3 | # Each line is a file pattern followed by one or more owners.
4 |
5 | # These owners will be the default owners for everything in
6 | # the repo. Unless a later match takes precedence,
7 | # @global-owner1 and @global-owner2 will be requested for
8 | # review when someone opens a pull request.
9 | * @wildanie12 @msazzuhair @jeroapriyansah @mhaikalla @danz63 @AdhyWiranto44 @ikr4mm @mhaikalla @dipras @yezki @feri-irawan @maulan909
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3 | patreon: # Replace with a single Patreon username
4 | open_collective: # Replace with a single Open Collective username
5 | ko_fi: # Replace with a single Ko-fi username
6 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
7 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
8 | liberapay: # Replace with a single Liberapay username
9 | issuehunt: # Replace with a single IssueHunt username
10 | otechie: # Replace with a single Otechie username
11 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
12 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 | Closes
2 |
3 |
4 | ## Deskripsi (Description)
5 |
6 |
7 | - [ ] saya menambahkan materi basic baru
8 | - [ ] saya memperbaiki materi basic yang sudah ada
9 | - [ ] saya menambahkan materi utility baru
10 | - [ ] saya memperbaiki materi utility sudah ada
11 | - [ ] saya menambahkan dokumentasi/artikel baru
12 | - [ ] saya memperbaiki dokumentasi/artikel yang sudah ada
13 | - [ ] saya menambahkan algoritma baru
14 | - [ ] saya memperbaiki algoritma yang sudah ada
15 |
16 | ## Contributor Requirements (Syarat Kontributor)
17 |
18 | - [ ] saya sudah membaca _(I have read)_ [CONTRIBUTING](https://github.com/bellshade/PHP/blob/main/CONTRIBUTING.md) dan sudah menyetujui semua
19 | - [ ] saya telah menambahkan docstring yang memberikan penjelasan maksud dari kode yang saya buat
20 | - [ ] saya sudah membuat artikel `README.md` tentang materi yang saya buat
21 | - [ ] saya menggunakan bahasa indonesia untuk memberikan penjelasan dari kode yang saya buat
22 |
23 | ## Environment
24 |
25 | saya menggunakan (I am using):
26 |
27 | - `os` = `linux / windows / macOS`
28 |
29 | ## Testing
30 |
31 | - [ ] Codesniffer PSR-12 `phpcs`
32 | - [ ] Codesniffer autofix `phpcbf`
33 | - [ ] Unit testing PHPUnit
34 |
35 | ## Maintainer
36 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/.github/workflows/checkCode.yml:
--------------------------------------------------------------------------------
1 | name: CI PHP PSR-12 Linting
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 | paths:
9 | - "**.php"
10 | - "phpcs.xml"
11 | - ".github/workflows/phpcs.yml"
12 |
13 | jobs:
14 | build:
15 |
16 | runs-on: ubuntu-latest
17 |
18 | steps:
19 | - uses: actions/checkout@v2
20 |
21 | - name: Validate composer.json and composer.lock
22 | run: composer validate --strict
23 |
24 | - name: Cache Composer packages
25 | id: composer-cache
26 | uses: actions/cache@v2
27 | with:
28 | path: vendor
29 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
30 | restore-keys: |
31 | ${{ runner.os }}-php-
32 |
33 | - name: Install dependencies
34 | run: composer install --prefer-dist --no-progress
35 |
36 | - name: Run phpcs
37 | run: composer run-script phpcs
38 |
39 | - name: Check PHP syntax errors
40 | uses: overtrue/phplint@3.0.3
41 |
42 | - name: PHPUnit Tests
43 | run: composer phpunit
44 |
--------------------------------------------------------------------------------
/.github/workflows/codeql.yml:
--------------------------------------------------------------------------------
1 | name: "CodeQL"
2 |
3 | on:
4 | push:
5 | branches: [ "main" ]
6 | pull_request:
7 | branches: [ "main" ]
8 | schedule:
9 | - cron: "25 1 * * 6"
10 |
11 | jobs:
12 | analyze:
13 | name: Analyze
14 | runs-on: ubuntu-latest
15 | permissions:
16 | actions: read
17 | contents: read
18 | security-events: write
19 |
20 | strategy:
21 | fail-fast: false
22 | matrix:
23 | language: [ javascript ]
24 |
25 | steps:
26 | - name: Checkout
27 | uses: actions/checkout@v3
28 |
29 | - name: Initialize CodeQL
30 | uses: github/codeql-action/init@v2
31 | with:
32 | languages: ${{ matrix.language }}
33 | queries: +security-and-quality
34 |
35 | - name: Autobuild
36 | uses: github/codeql-action/autobuild@v2
37 |
38 | - name: Perform CodeQL Analysis
39 | uses: github/codeql-action/analyze@v2
40 | with:
41 | category: "/language:${{ matrix.language }}"
42 |
--------------------------------------------------------------------------------
/.github/workflows/markdown-linter.yml:
--------------------------------------------------------------------------------
1 | name: Markdown Linter
2 |
3 | on:
4 | push:
5 | branches: [main]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - name: Checkout repository
15 | uses: actions/checkout@v2
16 |
17 | - name: Setup Node.js environment
18 | uses: actions/setup-node@v2
19 | with:
20 | node-version: '16'
21 |
22 | - name: Install dependencies
23 | run: npm install
24 |
25 | - name: Lint Markdown files
26 | run: npx markdownlint '**/*.md'
27 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | **/storage/*
3 | tasks.md
4 | .env
5 | silabus.txt
6 |
7 | node_modules
--------------------------------------------------------------------------------
/.htaccess:
--------------------------------------------------------------------------------
1 | RewriteEngine on
2 | RewriteCond $1 !^(index\.php|resources|robots\.txt)
3 | RewriteCond %{REQUEST_FILENAME} !-f
4 | RewriteCond %{REQUEST_FILENAME} !-d
5 | RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
--------------------------------------------------------------------------------
/.markdownlint.json:
--------------------------------------------------------------------------------
1 | {
2 | "MD033": false,
3 | "MD041": false,
4 | "MD013": false
5 | }
--------------------------------------------------------------------------------
/.markdownlintignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | **/storage/*
3 | tasks.md
4 | .env
5 | silabus.txt
6 |
7 | node_modules
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | *.md
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Bellshade
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/algorithms/BackTracking/PathFinding/README.md:
--------------------------------------------------------------------------------
1 | ## Pathfinding menggunakan Backtracking
2 |
3 | Pathfinding adalah salah satu implementasi algoritma backtracking
4 | yang tujuannya adalah menemukan jalan dari posisi awal sampai ke tujuan.
5 |
6 | Implementasinya yaitu dengan menggunakan array matrix / array 2 dimensi sebagai
7 | Peta yang akan dilalui oleh algoritma pathfinding. Didalam peta tersebut terdapat
8 | kotak atau cell yang tidak dapat dilalui oleh pathfinding. Oleh karena itu,
9 | untuk mencapai tujuan, pathfinding harus mencari jalan dengan menggunakan algoritma backtracking
10 |
11 | Skenario:
12 |
13 | - parameter variabel x dan y digunakan untuk menentukan tempat berpijak sekarang
14 | - indeks baris dan kolom terakhir ditetapkan sebagai tujuan. [n(xArray)-1, n(yArray)-1]
15 |
16 | Algoritma ini dalam kalimat bahasa indonesia adalah sebagai berikut:
17 |
18 | 1. cek posisi [x, y] sekarang apakah sudah sampai tujuan yang diinginkan?
19 | > Jika ya: Tandai posisi ini sebagai langkah yang benar. hentikan langkah selanjutnya
20 | > Jika tidak: lakukan langkah berikutnya
21 |
22 | 2. cek posisi [x, y] sekarang apakah boleh dipijaki atau tidak?
23 | > jika ya:
24 | - Catat posisi sekarang [x, y] sebagai langkah yang benar
25 | - Bergerak kekanan dengan cara kembali ke langkah a (Rekursif) membawa nilai y+1
26 | > Jika berhasil: Tandai kekanan adalah jalan yang tepat, kembalikan nilai 1, hentikan langkah selanjutnya
27 | > Jika tidak: lanjut ke langkah selanjutnya
28 | - Bergerak kebawah dengan cara kembali ke langkah a (Rekursif) membawa nilai x+1
29 | > Jika berhasil: Tandai kebawah adalah jalan yang tepat, kembalikan nilai 1, hentikan langkah selanjutnya
30 | > Jika tidak: lanjut ke langkah selanjutnua
31 | - Di titik ini, tidak ada gerakan yang dapat dilakukan / Jalan Buntu
32 | - catat posisi sekarang [x, y] sebagai langkah yang salah
33 | - tandai posisi ini bukan jalan yang tepat dengan mengembalikan nilai 0 / false (Backtracking)
34 |
35 | > Jika tidak:
36 | - tandai posisi ini bukan jalan yang tepat dengan mengembalikan nilai 0 / false (Backtracking)
37 |
38 | Secara sederhana, algoritma ini menjalankan 2 action yaitu: bergerak kekanan dan kebawah secara terus menerus
39 | sampai tujuannya tercapai yaitu: berada di tujuan dan berada di tempat yang boleh dipijaki / tanpa rintangan.
40 | Jika tiap recursive tidak tercapai tujuannya, maka tidak akan terus mendalami
41 | kemungkinan action itu dan akan berpindah ke kemungkinan action lainnya
42 |
--------------------------------------------------------------------------------
/algorithms/BackTracking/README.md:
--------------------------------------------------------------------------------
1 | # Algoritma Backtracking
2 |
--------------------------------------------------------------------------------
/algorithms/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Algorithms
4 |
5 |
6 | ## Daftar isi
7 |
8 | - [BackTracking](https://github.com/bellshade/PHP/tree/main/algorithms/BackTracking)
9 | - [PathFinding](https://github.com/bellshade/PHP/tree/main/algorithms/BackTracking/PathFinding)
10 | - Sudoku - On progress
11 | - [Sorting](https://github.com/bellshade/PHP/tree/main/algorithms/Sorting)
12 | - Selection sort - On Progress
13 | - [Bubble sort](https://github.com/bellshade/PHP/tree/main/algorithms/Sorting/BubbleSort)
14 | - Insertion sort - On Progress
15 | - [Pop sort](https://github.com/bellshade/PHP/tree/main/algorithms/Sorting/PopSort)
16 | - [Search](https://github.com/bellshade/PHP/tree/main/algorithms/Searching)
17 | - [Linear Search](https://github.com/bellshade/PHP/tree/main/algorithms/Searching/Linear)
18 | - [Binary Search](https://github.com/bellshade/PHP/tree/main/algorithms/Searching/Binary)
19 | - [Jump Search](https://github.com/bellshade/PHP/tree/main/algorithms/Searching/Jump)
20 | - Ternary Search - On Progress
21 | - Interpolation Search - On progress
22 |
--------------------------------------------------------------------------------
/algorithms/Searching/Linear/LinearSearch.php:
--------------------------------------------------------------------------------
1 | hasil;
29 | }
30 |
31 | $index = 0;
32 | //perulangan untuk setiap array
33 | do {
34 | if ($array[$index] == $key) {
35 | //jika data ditemukan
36 | $this->hasil = true;
37 | //hentikan perulangan
38 | break;
39 | }
40 | //pencarian secara recursive
41 | if (is_array($array[$index])) {
42 | $this->cari($array[$index], $key);
43 | }
44 | $index++;
45 | } while ($index < $length);
46 |
47 | //kembalikan hasil keluaran
48 | return $this->hasil;
49 | }
50 | }
51 |
52 | //testing
53 | $array = [1, 2, 3, 4, 5, [6, 7, 12, 18], 8, 9, 10];
54 | $nilai1 = 37;
55 | $nilai2 = 12;
56 | $linear = new LinearSearch();
57 |
58 | $hasil1 = $linear->cari($array, $nilai1);
59 | $hasil2 = $linear->cari($array, $nilai2);
60 |
61 | //Tampilkan Hasil Pencarian
62 | echo '';
63 | echo 'Data Array :' . PHP_EOL;
64 | print_r($array);
65 |
66 | echo PHP_EOL . 'Pencarian Nilai ' . $nilai1 . ', Hasil : ' . PHP_EOL;
67 | echo (!$hasil1) ? 'Tidak Ada ' : 'Ada ';
68 |
69 | echo PHP_EOL . 'Pencarian Nilai ' . $nilai2 . ', Hasil : ' . PHP_EOL;
70 | echo (!$hasil2) ? 'Tidak Ada ' : 'Ada ';
71 |
--------------------------------------------------------------------------------
/algorithms/Searching/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Searching Algorithms
4 |
5 |
--------------------------------------------------------------------------------
/algorithms/Sorting/BubbleSort/BubbleSort.php:
--------------------------------------------------------------------------------
1 | = 0; $index--) {
39 | for ($secondIndex = 0; $secondIndex <= $index; $secondIndex++) {
40 | // Jika data ke-1 lebih besar dari data ke-2 maka tukar posisinya
41 | if ($array[$secondIndex] > $array[$secondIndex + 1]) {
42 | // Lakukan penukaran posisi data
43 | $temp = $array[$secondIndex + 1];
44 | $array[$secondIndex + 1] = $array[$secondIndex];
45 | $array[$secondIndex] = $temp;
46 | }
47 | }
48 | }
49 |
50 | return $array;
51 | }
52 | }
53 |
54 |
55 | /**
56 | * Bubble Sort (Sorting)
57 | * --------------------------
58 | */
59 | echo 'Bubble Sort (Sorting) ';
60 |
61 | $inputTest = [];
62 |
63 | foreach (range(1, 10) as $key) {
64 | $inputTest[] = rand(-100, 100);
65 | }
66 |
67 | $bubbleSort = (new BubbleSort())->bubbleSort($inputTest);
68 |
69 | echo '';
70 | echo 'Input array sebelum di jalankan BubbleSort' . PHP_EOL;
71 | print_r($inputTest);
72 | echo ' ';
73 |
74 | echo '';
75 | echo 'Input array setelah di jalankan BubbleSort' . PHP_EOL;
76 | print_r($bubbleSort);
77 | echo ' ';
78 |
--------------------------------------------------------------------------------
/algorithms/Sorting/CountingSort/CountingSort.php:
--------------------------------------------------------------------------------
1 | array = $array;
32 | }
33 |
34 | public function setMaxValue(int $maxValue)
35 | {
36 | $this->countArray = array_fill(0, $maxValue + 1, 0);
37 | return $this;
38 | }
39 |
40 | public function sort(): array
41 | {
42 | // Proses penghitungan angka
43 | foreach ($this->array as $num) {
44 | $this->countArray[$num]++;
45 | }
46 | echo "\nArray : ";
47 | print_r($this->array);
48 |
49 | echo "CountArray : ";
50 | print_r($this->countArray);
51 |
52 | // Proses modifikasi array akumulasi untuk pengurutan
53 | $previousCount = 0;
54 | foreach ($this->countArray as $index => $count) {
55 | $this->countArray[$index] = $count + $previousCount;
56 | $previousCount = $this->countArray[$index];
57 | }
58 | echo "CountArray Modified (Acuan penempatan) : ";
59 | print_r($this->countArray);
60 |
61 | $sortedArray = array_fill(0, count($this->array), 0);
62 | foreach ($this->array as $num) {
63 | $indexPlacement = $this->countArray[$num] - 1;
64 | $sortedArray[$indexPlacement] = $num;
65 | $this->countArray[$num]--;
66 | }
67 |
68 | echo "Hasil pengurutan : ";
69 | print_r($sortedArray);
70 |
71 | return $sortedArray;
72 | }
73 | }
74 |
75 | echo '';
76 | $input = [2, 5, 1, 2, 9, 6, 4, 7];
77 | $expected = [1, 2, 2, 4, 5, 6, 7, 9];
78 | $actual = (new CountingSort($input))->setMaxValue(9)->sort();
79 | echo ' ';
80 |
--------------------------------------------------------------------------------
/algorithms/Sorting/README.md:
--------------------------------------------------------------------------------
1 | # Algoritma Sorting
2 |
--------------------------------------------------------------------------------
/algorithms/Sorting/SelectionSort/SelectionSort.php:
--------------------------------------------------------------------------------
1 | Selection Sort Algorithm" . PHP_EOL;
50 | // Cetak array sebelum diurutkan
51 | echo "Data sebelum disort: " . json_encode($items) . "\n";
52 | // Buat objek dari class SelectionSort
53 | $selectionSort = (new SelectionSort())->selectionSort($items, $length);
54 | // Cetak hasil
55 | echo "Data setelah disort: " . json_encode($selectionSort) . "\n";
56 |
--------------------------------------------------------------------------------
/algorithms/autoload.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/assets/content/basics/7_array_mendalam/array pop __setelah_pop.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/assets/content/basics/7_array_mendalam/array push __sebelum_push.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/assets/content/basics/7_array_mendalam/array shift __setelah_shift.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/assets/content/basics/7_array_mendalam/array unshift __sebelum_unshift.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/assets/content/basics/7_array_mendalam/memori_array.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/content/basics/7_array_mendalam/memori_array.png
--------------------------------------------------------------------------------
/assets/content/basics/8_fungsi_dasar/comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/content/basics/8_fungsi_dasar/comment.png
--------------------------------------------------------------------------------
/assets/content/cekhere.svg:
--------------------------------------------------------------------------------
1 | Contoh Kode Contoh Kode > >
--------------------------------------------------------------------------------
/assets/css/global.css:
--------------------------------------------------------------------------------
1 | @font-face {
2 | font-family: "Poppins";
3 | font-style: normal;
4 | font-weight: 400;
5 | src: url(../webfonts/Poppins-Regular.ttf) format("ttf");
6 | }
7 |
8 | .breadcrumb-item.active {
9 | color: #c9c9c9;
10 | font-weight: 500;
11 | }
12 | .readme-content {
13 | font-family: "Poppins", sans-serif;
14 | font-size: 16px;
15 | }
16 |
--------------------------------------------------------------------------------
/assets/css/markdown-style.css:
--------------------------------------------------------------------------------
1 | body {
2 | background: #ddd;
3 | background-image: url("../images/background-pattern.jpg");
4 | }
5 |
6 | /* -- Markdown -- */
7 | .readme-content a {
8 | text-decoration: none;
9 | color: rgb(7, 88, 97);
10 | }
11 | .readme-content blockquote {
12 | padding: 12px 24px;
13 | border-left: 4px solid #ddd;
14 | color: #6a6a6a;
15 | margin: 24px 0;
16 | }
17 | .readme-content blockquote p {
18 | margin: 0;
19 | }
20 | .readme-content h2 {
21 | padding-bottom: 12px;
22 | margin-top: 24px;
23 | margin-bottom: 24px;
24 | font-size: 28px;
25 | border-bottom: 1px solid #ddd;
26 | }
27 | .readme-content h3 {
28 | font-size: 20px;
29 | }
30 | .readme-content h4 {
31 | font-size: 16px;
32 | padding: 8px 16px;
33 | border-left: 4px solid #ddd;
34 | }
35 |
36 | /* -- Page -- */
37 |
38 | .logo-wrapper {
39 | height: 64px;
40 | mix-blend-mode: darken;
41 | }
42 |
43 | .w-square-64 {
44 | width: 64px;
45 | height: 64px;
46 | }
47 |
48 | .materi-wrapper {
49 | width: 400px;
50 | position: fixed;
51 | bottom: 16px;
52 | right: 16px;
53 | transition: all 500ms ease-out;
54 | transform: translateY(calc(100% - 40px));
55 | }
56 | .materi-wrapper .card-header {
57 | cursor: pointer;
58 | }
59 | .materi-wrapper.materi-shown {
60 | transform: translateY(0);
61 | }
62 | .materi-wrapper.materi-hidden {
63 | transform: translateY(calc(100% + 40px));
64 | }
65 | .materi-wrapper button {
66 | transition: all 500ms ease-out;
67 | transform: rotate(0);
68 | }
69 | .materi-wrapper button:focus {
70 | outline: none !important;
71 | border: none !important;
72 | box-shadow: none;
73 | }
74 | .materi-wrapper button.rotated {
75 | transform: rotate(-180deg);
76 | }
77 | .materi-wrapper .card-header {
78 | background-color: #4f5b93;
79 | }
80 |
81 | code {
82 | font-size: 0.875em;
83 | color: #d63384;
84 | word-wrap: break-word;
85 | background: #f1f1f1;
86 | padding: 4px;
87 | border-radius: 6px;
88 | }
89 | pre {
90 | background: #f1f1f1;
91 | padding: 16px;
92 | border-left: 4px solid #ddd;
93 | }
94 |
--------------------------------------------------------------------------------
/assets/images/14-7-1-360px-Opened_light_switch.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/14-7-1-360px-Opened_light_switch.jpg
--------------------------------------------------------------------------------
/assets/images/14-7-2-527px-Light_switch_inside_explained.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/14-7-2-527px-Light_switch_inside_explained.jpg
--------------------------------------------------------------------------------
/assets/images/8.1pouring tea realistic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/8.1pouring tea realistic.jpg
--------------------------------------------------------------------------------
/assets/images/Webysther_20160423_-_Elephpant.svg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/Webysther_20160423_-_Elephpant.svg.png
--------------------------------------------------------------------------------
/assets/images/background-pattern.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/background-pattern.jpg
--------------------------------------------------------------------------------
/assets/images/bellshade-inline.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/bellshade-inline.png
--------------------------------------------------------------------------------
/assets/images/getting-started.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/getting-started.png
--------------------------------------------------------------------------------
/assets/images/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/icon.png
--------------------------------------------------------------------------------
/assets/images/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/logo.png
--------------------------------------------------------------------------------
/assets/images/mpdf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/mpdf.png
--------------------------------------------------------------------------------
/assets/images/phpicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/phpicon.png
--------------------------------------------------------------------------------
/assets/images/phplogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/images/phplogo.png
--------------------------------------------------------------------------------
/assets/webfonts/Poppins-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/Poppins-Regular.ttf
--------------------------------------------------------------------------------
/assets/webfonts/Poppins-Regular.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/Poppins-Regular.woff2
--------------------------------------------------------------------------------
/assets/webfonts/fa-brands-400.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-brands-400.eot
--------------------------------------------------------------------------------
/assets/webfonts/fa-brands-400.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-brands-400.ttf
--------------------------------------------------------------------------------
/assets/webfonts/fa-brands-400.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-brands-400.woff
--------------------------------------------------------------------------------
/assets/webfonts/fa-brands-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-brands-400.woff2
--------------------------------------------------------------------------------
/assets/webfonts/fa-regular-400.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-regular-400.eot
--------------------------------------------------------------------------------
/assets/webfonts/fa-regular-400.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-regular-400.ttf
--------------------------------------------------------------------------------
/assets/webfonts/fa-regular-400.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-regular-400.woff
--------------------------------------------------------------------------------
/assets/webfonts/fa-regular-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-regular-400.woff2
--------------------------------------------------------------------------------
/assets/webfonts/fa-solid-900.eot:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-solid-900.eot
--------------------------------------------------------------------------------
/assets/webfonts/fa-solid-900.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-solid-900.ttf
--------------------------------------------------------------------------------
/assets/webfonts/fa-solid-900.woff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-solid-900.woff
--------------------------------------------------------------------------------
/assets/webfonts/fa-solid-900.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/assets/webfonts/fa-solid-900.woff2
--------------------------------------------------------------------------------
/basics/10_file_handling/1_membaca_file_dan_folder.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Membaca File PHP ";
6 |
7 | echo "Pertama buat variabel yang mengarahkan ke lokasi file berada
8 |
9 | // Letak filenya
10 | file = '../../assets/content/basics/10_file_handling/file_handling.txt';
11 |
12 | // Membuka file yang ingin dibaca
13 | open = fopen(file, 'r');
14 |
15 | // Mencari size dari filenya
16 | size = filesize(file);
17 |
18 | // Untuk membaca sebuah file maka gunakan lah fread
19 | filedata = fread(open, size);
20 |
21 | print_r(filedata);
22 |
23 | Hasil print yang akan di dapatkan adalah sebagai berikut:
24 |
25 | ";
26 |
27 | // Letak filenya
28 | $file = '../../assets/content/basics/10_file_handling/file_handling.txt';
29 |
30 | // Membuka file yang ingin dibaca
31 | $open = fopen($file, 'r');
32 |
33 | // Mencari size dari filenya
34 | $size = filesize($file);
35 |
36 | // Untuk membaca sebuah file maka gunakan lah fread
37 | $filedata = fread($open, $size);
38 |
39 | print_r($filedata);
40 |
--------------------------------------------------------------------------------
/basics/10_file_handling/2_create_file_folder.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Membuat Folder dan File dengan PHP ";
6 |
7 | echo "Untuk membuat folder pada PHP gunakan mkdir()
8 |
9 | // Menyimpan data untuk membuat Folder ke dalam Variabel
10 | dir = 'storage';
11 |
12 | // Identitas File yang akan dibuat
13 | nama_file = 'test.txt';
14 | konten_file = 'contoh content file';
15 |
16 | // Mengecek apakah folder storage belum ada
17 | if (!is_dir(dir)) {
18 | // Membuat Folder jika belum ada
19 | mkdir(dir);
20 | }
21 |
22 |
23 | // fopen sebelum membuat file
24 | open = fopen(dir . '/' . nama_file, 'w');
25 |
26 | // fwrite untuk membuat sebuah file dan kontennya
27 | fwrite(open, konten_file);
28 |
29 | // Menutup File
30 | fclose(open);
31 |
32 | Hasil nya dapat dilihat setelah halaman ini di load silakan cek folder storage seharusnya sudah ada folder dan juga file baru di dalamnya:
33 |
34 | ";
35 |
36 | // Menyimpan data untuk membuat Folder ke dalam Variabel
37 | $dir = 'storage';
38 |
39 | // Identitas File yang akan dibuat
40 | $nama_file = 'test.txt';
41 | $konten_file = 'contoh content file';
42 |
43 | // Mengecek apakah folder storage belum ada
44 | if (!is_dir($dir)) {
45 | // Membuat Folder jika belum ada
46 | mkdir($dir);
47 | }
48 |
49 | // fopen sebelum membuat file
50 | $open = fopen($dir . '/' . $nama_file, 'w');
51 |
52 | // fwrite untuk membuat sebuah file dan kontennya
53 | fwrite($open, $konten_file);
54 |
55 | // Menutup File
56 | fclose($open);
57 |
--------------------------------------------------------------------------------
/basics/10_file_handling/3_write_file.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Menuliskan (Write) File dengan PHP ";
6 |
7 | echo "Untuk write file pada PHP gunakan fwrite()
8 |
9 | // Folder dari file
10 | dir = 'storage';
11 |
12 | // Identitas File yang akan diubah
13 | nama_file = 'test.txt';
14 |
15 | // fopen sebelum membuat file
16 | open = fopen(dir . '/' . nama_file, 'w');
17 |
18 | // fwrite untuk membuat sebuah file dan kontennya
19 | fwrite(open, konten_file);
20 |
21 | // Menutup File
22 | fclose(open);
23 |
24 | Hasil nya dapat dilihat dengan mengecek isi dari file test.txt. Sebelum menjalankan file ini pastikan bahwa anda sudah mencoba 2_create_file_folder:
25 |
26 | ";
27 |
28 | // Folder dari file
29 | $dir = 'storage';
30 |
31 | // Identitas File yang akan diubah
32 | $nama_file = 'test.txt';
33 |
34 | // fopen sebelum membuat file
35 | $open = fopen($dir . '/' . $nama_file, 'w');
36 |
37 | // fwrite untuk membuat sebuah file dan kontennya
38 | fwrite($open, 'Ini adalah hasil dari write yang telah dilakukan');
39 |
40 | // Menutup File
41 | fclose($open);
42 |
--------------------------------------------------------------------------------
/basics/10_file_handling/4_delete_file.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Menghapus (Delete) File dengan PHP ";
6 |
7 | echo "Untuk delete file pada PHP gunakan unlink()
8 |
9 | // Folder dari file
10 | dir = 'storage';
11 |
12 | // Identitas File yang akan diubah
13 | nama_file = 'test.txt';
14 |
15 | // Menggunakan unlink() untuk menghapus File
16 | if (!unlink( dir . / . nama_file)) {
17 | echo (nama_file tidak bisa di hapus);
18 | }
19 | else {
20 | echo (nama_file telah dihapus);
21 | }
22 |
23 | Hasil nya dapat dilihat dengan mengecek isi dari file test.txt. Sebelum menjalankan file ini pastikan bahwa anda sudah mencoba 2_create_file_folder:
24 |
25 | ";
26 |
27 | // Folder dari file
28 | $dir = 'storage';
29 |
30 | // Identitas File yang akan diubah
31 | $nama_file = 'test.txt';
32 |
33 | // Menggunakan unlink() untuk menghapus File
34 | if (!unlink($dir . '/' . $nama_file)) {
35 | echo ("$nama_file tidak bisa di hapus");
36 | } else {
37 | echo ("$nama_file telah dihapus");
38 | }
39 |
--------------------------------------------------------------------------------
/basics/10_file_handling/5_upload_file.php:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | Upload - File Handling
21 |
22 |
23 |
24 |
25 | Upload File
26 |
27 |
28 | Berikut contoh penaganan file Upload
29 |
30 |
31 | Contoh
32 |
33 |
38 |
39 |
40 | ";
52 | $uploadOk = 1;
53 | } else {
54 | echo "File Bukan Gambar";
55 | $uploadOk = 0;
56 | }
57 | // Cek apakah file sudah ada atau belum
58 | if (file_exists($target_file)) {
59 | echo "Maaf, file yang di upload sudah ada";
60 | $uploadOk = 0;
61 | }
62 | // Cek Apakah Upload Ok 0 atau bukan
63 | if ($uploadOk == 0) {
64 | echo "Maaf, file anda gagal di upload";
65 | // Upload file kalau semua aman
66 | } else {
67 | // Memindahkan file yang diupload ke folder storage
68 | if (move_uploaded_file($_FILES["fileUpload"]["tmp_name"], $target_file)) {
69 | echo "File " . htmlspecialchars(basename($_FILES["fileUpload"]["name"])) . " sudah di upload";
70 | } else {
71 | echo "Upload Error";
72 | }
73 | }
74 | }
75 | ?>
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/basics/10_file_handling/6_validation_file.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Validasi (Validation) File dengan PHP ";
6 |
7 | echo "Untuk validasi file pada PHP ada beragam function yang bisa digunakan
8 |
9 | // Folder dari file
10 | dir = 'storage';
11 |
12 | // Identitas File yang akan diubah
13 | nama_file = 'test.txt';
14 |
15 | Hasil nya dapat dilihat dengan mengecek isi dari file test.txt. Sebelum menjalankan file ini pastikan bahwa anda sudah mencoba 2_create_file_folder:
16 | ";
17 |
18 | // Folder dari file
19 | $dir = 'storage';
20 |
21 | // Identitas File yang akan diubah
22 | $nama_file = 'test.txt';
23 |
24 | // Adding Space
25 | echo '
26 | filectime() ';
27 |
28 | // Filectime (Mengembalikan Tanggal Terakhir File Mengalami perubahan)
29 | print_r(date("F d Y H:i:s.", filectime($dir . '/' . $nama_file)));
30 |
31 | // Adding Space
32 | echo '
33 | filemtime() ';
34 |
35 | // Filectime (Mengembalikan Tanggal Terakhir File Mengalami perubahan)
36 | print_r(date("F d Y H:i:s.", filemtime($dir . '/' . $nama_file)));
37 |
38 | // Adding Space
39 | echo '
40 | filesize() ';
41 |
42 | // Filesize (Mengembalikan Ukuran dari file)
43 | print_r(filesize($dir . '/' . $nama_file));
44 |
45 | // Adding Space
46 | echo '
47 | filetype() ';
48 |
49 | // Filetype (Mengembalikan Tipe dari File)
50 | print_r(filetype($dir . '/' . $nama_file));
51 |
52 | // Adding Space
53 | echo '
54 | fileperms() ';
55 |
56 | // Fileperms (Mengembalikan Tipe dari File)
57 | print_r(fileperms($dir . '/' . $nama_file));
58 |
59 | // Adding Space
60 | echo '
61 | fileowner() ';
62 |
63 | // Fileowner (Mengembalikan Owner dari File)
64 | print_r(fileowner($dir . '/' . $nama_file));
65 |
66 | // Adding Space
67 | echo '
68 | is_dir() ';
69 |
70 | // Is_dir (Mengecek Direktori)
71 | print_r(is_dir($dir));
72 |
73 | // Adding Space
74 | echo '
75 | file_exists() ';
76 |
77 | // File_exists (Mengembalikan Apakah File ada atau tidak)
78 | print_r(file_exists($dir . '/' . $nama_file));
79 |
80 | // Adding Space
81 | echo '
82 | is_file() ';
83 |
84 | // Is_file (Mengembalikan Apakah File ada atau tidak)
85 | print_r(is_file($dir . '/' . $nama_file));
86 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/1_set_session.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 | // ----------------------------------------------
9 | echo "Membuat Session ";
10 |
11 | // Membuat session
12 | $_SESSION['nama'] = 'Feri Irawan';
13 | $_SESSION['tim'] = 'PHP';
14 |
15 | // Menampilkan semua session
16 | print_r($_SESSION);
17 |
18 | // Hasil:
19 | // Array
20 | // (
21 | // [nama] => Feri Irawan
22 | // [tim] => PHP
23 | // )
24 |
25 | echo "";
26 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/2_get_session.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 | // ----------------------------------------------
9 | echo "Membuat Session ";
10 |
11 | // Membuat session
12 | $_SESSION["nama"] = "Feri Irawan";
13 | $_SESSION["tim"] = "PHP";
14 |
15 | // Menampilkan semua session
16 | print_r($_SESSION);
17 |
18 | // Hasil:
19 | // Array
20 | // (
21 | // [nama] => Feri Irawan
22 | // [tim] => PHP
23 | // )
24 |
25 |
26 |
27 | // ----------------------------------------------
28 | echo "\n\nMengambil/Menampilkan Session ";
29 |
30 | // Menampilkan session
31 | echo $_SESSION["nama"] . PHP_EOL;
32 | echo $_SESSION["tim"];
33 |
34 | echo "";
35 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/3_update_session.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 | // ----------------------------------------------
9 | echo "Membuat Session ";
10 |
11 | // Membuat session
12 | $_SESSION["nama"] = "Feri Irawan";
13 | $_SESSION["tim"] = "PHP";
14 |
15 | // Menampilkan semua session
16 | print_r($_SESSION);
17 |
18 | // Hasil:
19 | // Array
20 | // (
21 | // [nama] => Feri Irawan
22 | // [tim] => PHP
23 | // )
24 |
25 |
26 |
27 | // ----------------------------------------------
28 | echo "\n\nMengubah Session ";
29 | echo "Mengubah session dengan key `nama` jadi `Wahyudi`\n\n";
30 |
31 | // Mengubah session
32 | $_SESSION["nama"] = "Wahyudi";
33 |
34 | // Menampilkan session
35 | print_r($_SESSION);
36 |
37 | // Hasil:
38 | // Array
39 | // (
40 | // [nama] => Wahyudi
41 | // [tim] => PHP
42 | // )
43 |
44 | echo "";
45 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/4_delete_session.php:
--------------------------------------------------------------------------------
1 | ";
7 |
8 | // ----------------------------------------------
9 | echo "Membuat Session ";
10 |
11 | // Membuat session
12 | $_SESSION['nama'] = 'Feri Irawan';
13 | $_SESSION['tim'] = 'PHP';
14 | $_SESSION['umur'] = '17';
15 |
16 | // Menampilkan semua session
17 | print_r($_SESSION);
18 |
19 | // Hasil:
20 | // Array
21 | // (
22 | // [nama] => Feri Irawan
23 | // [tim] => PHP
24 | // )
25 |
26 |
27 |
28 | // ----------------------------------------------
29 | echo "\n\nMenghapus Session Tertentu ";
30 | echo "Menghapus session dengan key `umur`\n\n";
31 |
32 | // Menghapus session
33 | unset($_SESSION['umur']);
34 |
35 | // Menampilkan
36 | echo "Menampilkan semua session yang tersisa:\n\n";
37 | print_r($_SESSION);
38 |
39 | // Hasil:
40 | // Array
41 | // (
42 | // [nama] => Feri Irawan
43 | // [tim] => PHP
44 | // )
45 |
46 |
47 |
48 | // ----------------------------------------------
49 | echo "\n\nMenghapus Semua Session ";
50 |
51 | // Menghapus session
52 | session_unset();
53 | session_destroy();
54 |
55 | // Menampilkan
56 | echo "Menampilkan semua session yang tersisa:\n\n";
57 | print_r($_SESSION);
58 |
59 | // Hasil:
60 | // Array
61 | // (
62 | // )
63 |
64 | // Hasilnya hanya menampilkan array kosong,
65 | // itu artinya berhasil menghapus session
66 |
67 | echo "";
68 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/5_set_cookie.php:
--------------------------------------------------------------------------------
1 | ";
8 |
9 | // ----------------------------------------------
10 | echo "Membuat Cookie ";
11 |
12 | if (!isset($_COOKIE['nama']) == "Feri Irawan") {
13 | // Jika belum ada cookie, maka buat cookie-nya
14 |
15 | // Membuat cookie yang bertahan 0 jam
16 | setcookie('nama', 'Feri Irawan');
17 |
18 | // Membuat cookie yang bertahan 1 jam
19 | setcookie('tim', 'PHP', time() + 3600);
20 |
21 | // Membuat cookie yang bertahan 1 jam di direktori `/basics/11_cookie_dan_session`
22 | setcookie('umur', '17', time() + 3600, "/basics/11_cookie_dan_session");
23 |
24 | // Membuat cookie yang bertahan 1 jam di direktori `/basics/11_cookie_dan_session` di domain http://localhost
25 | setcookie('buah_manis', 'Rambutan', time() + 3600, "/basics/11_cookie_dan_session", "localhost");
26 |
27 | // Membuat cookie yang bertahan 1 jam di direktori `/basics/11_cookie_dan_session` di domain https://localhost dengan koneksi yang aman (HTTPS)
28 | setcookie('buah_masam', 'Belimbing', time() + 3600, "/basics/11_cookie_dan_session", "localhost", true);
29 |
30 | // Membuat cookie yang bertahan 1 jam di direktori `/basics/11_cookie_dan_session` hanya di domain http://localhost dengan protocol HTTP
31 | setcookie('buah_pahit', 'Pare', time() + 3600, "/basics/11_cookie_dan_session", "localhost", true, true);
32 |
33 | // Setelah itu tampilkan teks
34 | echo "Cookie berhasil dibuat. Refresh halaman ini sekali lagi!";
35 | } else {
36 | // Jika halaman telah direfresh dan cookie sudah dibuat,
37 | // maka tampilkan semua cookie yang ada
38 |
39 | // Menampilkan semua cookie
40 | print_r($_COOKIE);
41 |
42 | // Hasil:
43 | // Array
44 | // (
45 | // [nama] => Feri Irawan
46 | // [umur] => 17
47 | // [buah_manis] => Rambutan
48 | // [buah_masam] => Belimbing
49 | // [buah_pahit] => Pare
50 | // [tim] => PHP
51 | // )
52 |
53 | // Hasil yang tampil mungkin tidak sama (lebih banyak)
54 | // itu karna terdapat cookie lain yang telah disematkan sebelumnya, atau disematkan oleh server lain
55 | }
56 |
57 | echo "";
58 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/6_update_cookie.php:
--------------------------------------------------------------------------------
1 | ";
8 |
9 | // // Mengecek apakah user sudah memiliki cookie dengan key `tim`
10 | if (!isset($_COOKIE['tim'])) {
11 | echo "Oops, harap buka file 5_set_cookie.php terlebih dahulu untuk membuat cookie.\nSetelah itu kembali ke halaman ini dan refresh!";
12 | } else {
13 | // Jika sudah ada cookie `tim`
14 | echo "Mengubah Cookie dengan key `tim` ";
15 | echo "Cookie yang awalnya tim PHP diubah jadi tim JavaScript ";
16 |
17 | // Mengubah nilai cookie `tim` = `PHP` menjadi `tim` = `JavaScript`
18 | // Dan mengubah waktu kedaluwarsa yang awalnya 1 jam jadi 30 menit
19 | setcookie('tim', 'JavaScript', time() + 1800);
20 | }
21 |
22 |
23 | echo "";
24 |
--------------------------------------------------------------------------------
/basics/11_cookie_dan_session/7_delete_cookie.php:
--------------------------------------------------------------------------------
1 | ";
8 |
9 | echo "Menghapus Cookie ";
10 |
11 | // Mengosongkan value
12 | // Dan membuat cookie telah kedaluarsa 1 jam yang lalu
13 | setcookie("buah_masam", "", time() - 3600);
14 |
15 | echo "Cookie dengan key `buah_masam` berhasil dihapus";
16 |
17 | echo "";
18 |
--------------------------------------------------------------------------------
/basics/12_database_dasar_prosedural/2_connect.php:
--------------------------------------------------------------------------------
1 | ';
4 |
5 | /**
6 | * Memanggil file koneksi ke database dan
7 | * agar dapat menggunakan variabel `$connect` didalamnya
8 | */
9 | require_once('2_connect.php');
10 |
11 | $tabel = '12_database_dasar_prosedural_buku';
12 | $id = 6; // ID dari baris data yang akan dihapus
13 |
14 | echo 'ID yang akan dihapus: ' . $id;
15 | $query = mysqli_query($connect, "DELETE FROM $tabel WHERE id = '$id'");
16 | echo 'Baris yang terpengaruh: ' . mysqli_affected_rows($connect), PHP_EOL;
17 |
18 | echo '';
19 |
--------------------------------------------------------------------------------
/basics/12_database_dasar_prosedural/3_query_update.php:
--------------------------------------------------------------------------------
1 | ';
4 |
5 | /**
6 | * Memanggil file koneksi ke database dan
7 | * agar dapat menggunakan variabel `$connect` didalamnya
8 | */
9 | require_once('2_connect.php');
10 |
11 |
12 | $tabel = '12_database_dasar_prosedural_buku';
13 | $id = 1;
14 | $judul = 'Belajar pemrograman PHP dengan mudah';
15 |
16 | echo 'ID buku yang akan update: ' . $id, PHP_EOL;
17 | echo 'judul yang akan diganti: ' . $judul, PHP_EOL;
18 | echo 'Sedang mengupdate ...', PHP_EOL;
19 | $query = mysqli_query($connect, "UPDATE $tabel SET judul = '$judul' WHERE id = '$id'");
20 | echo 'Baris yang terpengaruh: ' . mysqli_affected_rows($connect) . ' baris', PHP_EOL;
21 |
22 | echo '';
23 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/1_prosedural_dan_oop.php:
--------------------------------------------------------------------------------
1 | param[$nama] = $nilai;
13 | }
14 |
15 | public function get($nama)
16 | {
17 | return isset($this->param[$nama]) ? $this->param[$nama] : null;
18 | }
19 | }
20 |
21 | //driven
22 | $test = new Contoh('nama', 'Bellshade');
23 | echo $test->get('nama');
24 |
25 | //.End of OOP
26 |
27 | //Prosedural
28 | function newContoh()
29 | {
30 | return array();
31 | }
32 |
33 | function setContoh(&$param, $nama, $nilai)
34 | {
35 | return $param[$nama] = $nilai;
36 | }
37 |
38 | function getContoh($param, $nama)
39 | {
40 | return isset($param[$nama]) ? $param[$nama] : null;
41 | }
42 |
43 | //penggunaan prosedural
44 | $test = newContoh();
45 | setContoh($test, 'nama', 'Bellshade');
46 | echo getContoh($test, 'nama');
47 |
48 | //.Prosedural
49 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/2_class_and_object.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Membuat class di PHP ";
6 |
7 | echo "class Kelas {
8 |
9 | }";
10 | class Kelas
11 | {
12 | }
13 | echo " ";
14 |
15 | echo "Membuat instance dari class",PHP_EOL;
16 | echo " ";
17 | echo "namaVariable = new namaClassNya();",PHP_EOL;
18 | echo "namaVariable2 = new namaClassNya();";
19 |
20 | echo " ";
21 | $kelas1 = new Kelas();
22 | $kelas2 = new Kelas();
23 | echo "Hasilnya Jika Di var_dump()",PHP_EOL;
24 | echo " ";
25 | var_dump($kelas1);
26 | var_dump($kelas2);
27 |
28 | echo "";
29 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/3_property_and_method.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | echo "Membuat Properti dan Method di PHP ";
6 |
7 | echo "class Kelas {
8 |
9 | //Deklarasi Properti
10 | public namaProperti = 'Nilai Properti';
11 | public namaPropertiDua = 2;
12 |
13 | //Deklarasi Method
14 | public function namaMethod()
15 | {
16 | //Perintah Apa saja
17 | echo 'Method';
18 | }
19 | }";
20 |
21 | class Kelas
22 | {
23 | // Deklarasi Properti
24 | public $namaProperti = 'Nilai Properti';
25 | public $namaPropertiDua = 2;
26 |
27 | //Deklarasi Method
28 | public function namaMethod()
29 | {
30 | //Perintah Apa saja
31 | echo 'Method';
32 | }
33 | }
34 |
35 | echo " ";
36 | $kelas1 = new Kelas();
37 | $kelas2 = new Kelas();
38 | echo " ";
39 | echo "Hasil Salah satu Property Jika Di var_dump()",PHP_EOL;
40 | var_dump($kelas1->namaProperti);
41 |
42 | echo " ";
43 | echo "Hasil Method Saat dipanggil",PHP_EOL;
44 | $kelas2->namaMethod();
45 |
46 | echo "";
47 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/4_constructor_destructor.php:
--------------------------------------------------------------------------------
1 | Objek dari kelas `SebuahKelas` dibuat __construct() dipanggil ";
13 | }
14 |
15 | /**
16 | * ini adalah method yang menyimulasikan penggunaan kelas biasa (method biasa)
17 | * jika dipanggil, akan menampilkan pesan halo
18 | */
19 | public function sapaHalo()
20 | {
21 | echo "Halo, ini adalah keluaran dari method `sapaHalo()` di kelas ini ";
22 | }
23 |
24 | /**
25 | * Sama dengan method `sapaHalo` diatas, ini juga untuk
26 | * menyimulasikan penggunaan kelas seperti biasanya.
27 | * method seperti ini akan dijalankan sebelum __destruct()
28 | */
29 | public function kasihHukuman($kalimat, $jumlahLoop)
30 | {
31 | echo "---- ini hukuman --------- ";
32 | for ($i = 0; $i < $jumlahLoop; $i++) {
33 | echo $kalimat . ' ';
34 | }
35 | echo "-------- ";
36 | }
37 |
38 | /**
39 | * Destructor dibuat dengan method yang dinamai dengan `__destruct()`
40 | * method destruct ini akan dijalankan saat objek sudah selesai dipakai.
41 | */
42 | public function __destruct()
43 | {
44 | echo "Penggunaan dari objek ini sudah selesai __destruct() dipanggil ";
45 | }
46 | }
47 |
48 | // Instantiasi objek dari kelas `SebuahKelas` dan menggunakan beberapa methodnya
49 | // __construct() akan dijalankan
50 | $sebuahKelas = new SebuahKelas();
51 | $sebuahKelas->sapaHalo();
52 | $sebuahKelas->kasihHukuman("Saya berjanji tidak akan mengulangi lagi", 20);
53 | // dan dititik ini `__destruct()` akan dijalankan karena penggunakaan objek kelas sudah selesai
54 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/4_constructor_destructor2.php:
--------------------------------------------------------------------------------
1 | nama = $nama;
20 | $this->jenisKelamin = $jenisKelamin;
21 | $this->alamat = $alamat;
22 | $this->email = $email;
23 | }
24 |
25 | /**
26 | * Method untuk menampilkan attribute yang sudah ditetapkan
27 | */
28 | public function getIdentitas()
29 | {
30 | echo 'Nama: ' . $this->nama . ' ';
31 | echo 'Jenis Kelamin: ' . $this->jenisKelamin . ' ';
32 | echo 'Alamat: ' . $this->alamat . ' ';
33 | echo 'Email: ' . $this->email . ' ';
34 | }
35 | }
36 |
37 | // Membuat objek pengguna
38 | $budi = new Pengguna('Budi', 'laku-laki', 'Jl. Jakarta', 'budi@mail.com');
39 |
40 | // Menampilkan nilai dari atribute menggunakan method `getIdentitas()`
41 | $budi->getIdentitas();
42 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/5_property_dan_method_static.php:
--------------------------------------------------------------------------------
1 | nama = $nama;
16 | $this->alamat = $alamat;
17 | }
18 |
19 | /**
20 | * Method static untuk melakukan operasi pada properti static
21 | */
22 | public static function setWaktuShift($shift)
23 | {
24 | self::$waktuShift = $shift;
25 | }
26 | }
27 |
28 | // Set waktu shift menggunakan method static
29 | // Karena method static, jadi tidak perlu ada instantiasi objek
30 | Kasir::setWaktuShift(2);
31 | echo 'Waktu Shift: ' . Kasir::$waktuShift;
32 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/6_constant_magic_constants.php:
--------------------------------------------------------------------------------
1 | tampilkanKonstanta();
34 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/6_constant_magic_constants2a.php:
--------------------------------------------------------------------------------
1 | jariJari = $jariJari;
20 | }
21 |
22 | // Method hitung luas
23 | public function hitungLuas()
24 | {
25 | return self::PI * $this->jariJari * $this->jariJari;
26 | }
27 | }
28 |
29 | // Instansiasi Pengguna
30 | $pengguna = new Pengguna();
31 |
32 | // Menampilkan pesan login
33 | $pengguna->login();
34 |
35 | // Instansiasi Lingkaran
36 | $lingkaran = new Lingkaran(10);
37 |
38 | // Menampilkan luas lingkaran
39 | echo "Luas lingkaran: " . $lingkaran->hitungLuas() . " cm \n";
40 |
41 | // Menampilkan pesan logout
42 | $pengguna->logout();
43 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/6_constant_magic_constants3.php:
--------------------------------------------------------------------------------
1 | lihatBaris();
59 | $demo->lihatFile();
60 | $demo->lihatDirektori();
61 | $demo->lihatNamespace();
62 | $demo->lihatFungsi();
63 | $demo->lihatKelas();
64 | $demo->lihatMetode();
65 | $demo->lihatTrait();
66 | $demo->lihatClass2();
67 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/7_setter_dan_getter.php:
--------------------------------------------------------------------------------
1 | tanggalLahir = '2000-01-01';
15 |
16 | // Mengakses nilai properti tanggalLahir untuk menghitung usia
17 | $dateTimeTanggalLahir = new DateTime($pengguna->tanggalLahir);
18 | $dateTimeHariIni = new DateTime();
19 | $hasilHitungUsia = $dateTimeHariIni->diff($dateTimeTanggalLahir)->y;
20 |
21 | // Mengeset properti usia dengan nilai dari variabel $hasilHitungUsia
22 | $pengguna->usia = $hasilHitungUsia;
23 |
24 | // Mengakses nilai properti tanggalLahir untuk ditampilkan
25 | // dalam format penulisan tanggal Indonesia
26 | $dateTimeTanggalLahir = new DateTime($pengguna->tanggalLahir);
27 | $formatterTanggal = new IntlDateFormatter('id_ID', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
28 | echo $formatterTanggal->format($dateTimeTanggalLahir); // 1 Januari 2000
29 |
30 | // Menampilkan baris baru
31 | echo PHP_EOL;
32 |
33 | // Mengakses nilai properti usia untuk ditampilkan
34 | echo "{$pengguna->usia} tahun"; // 23 tahun (2023)
35 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/7_setter_dan_getter2.php:
--------------------------------------------------------------------------------
1 | tanggalLahir = $tanggalLahir;
15 |
16 | // Mengakses nilai properti tanggalLahir untuk menghitung usia
17 | $dateTimeTanggalLahir = new DateTime($this->tanggalLahir);
18 | $dateTimeHariIni = new DateTime();
19 | $hasilHitungUsia = $dateTimeHariIni->diff($dateTimeTanggalLahir)->y;
20 |
21 | // Mengeset properti usia dengan nilai dari variabel $hasilHitungUsia
22 | $this->usia = $hasilHitungUsia;
23 | }
24 |
25 | // Getter untuk properti tanggalLahir
26 | public function getTanggalLahir()
27 | {
28 | // Mengakses nilai properti tanggalLahir untuk DIKEMBALIKAN
29 | // dalam format penulisan tanggal Indonesia
30 | $dateTimeTanggalLahir = new DateTime($this->tanggalLahir);
31 | $formatterTanggal = new IntlDateFormatter('id_ID', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
32 | return $formatterTanggal->format($dateTimeTanggalLahir);
33 | }
34 |
35 | // Getter untuk properti usia
36 | public function getUsia()
37 | {
38 | // Mengakses nilai properti usia untuk diformat dan DIKEMBALIKAN
39 | return "{$this->usia} tahun";
40 | }
41 | }
42 |
43 | // Instansiasi objek
44 | $pengguna = new Pengguna();
45 |
46 | // Mengeset nilai properti tanggalLahir melalui setter
47 | $pengguna->setTanggalLahir('2000-01-01');
48 |
49 | // Mengakses nilai properti tanggalLahir
50 | // yang telah diformat melalui getter-nya untuk ditampilkan
51 | echo $pengguna->getTanggalLahir(); // 1 Januari 2000
52 |
53 | // Menampilkan baris baru
54 | echo PHP_EOL;
55 |
56 | // Mengakses nilai properti usia
57 | // yang telah diformat melalui getter-nya untuk ditampilkan
58 | echo $pengguna->getUsia(); // 23 tahun (2023)
59 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/7_setter_dan_getter3.php:
--------------------------------------------------------------------------------
1 | tanggalLahir = $tanggalLahir;
15 |
16 | // Mengakses nilai properti tanggalLahir untuk menghitung usia
17 | $dateTimeTanggalLahir = new DateTime($this->tanggalLahir);
18 | $dateTimeHariIni = new DateTime();
19 | $hasilHitungUsia = $dateTimeHariIni->diff($dateTimeTanggalLahir)->y;
20 |
21 | // Mengeset properti usia dengan nilai dari variabel $hasilHitungUsia
22 | $this->usia = $hasilHitungUsia;
23 | }
24 |
25 | // Getter untuk properti tanggalLahir
26 | public function getTanggalLahir()
27 | {
28 | // Mengakses nilai properti tanggalLahir untuk DIKEMBALIKAN
29 | // dalam format penulisan tanggal Indonesia
30 | $dateTimeTanggalLahir = new DateTime($this->tanggalLahir);
31 | $formatterTanggal = new IntlDateFormatter('id_ID', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
32 | return $formatterTanggal->format($dateTimeTanggalLahir);
33 | }
34 |
35 | // Getter untuk properti usia
36 | public function getUsia()
37 | {
38 | // Mengakses nilai properti usia untuk diformat dan DIKEMBALIKAN
39 | return "{$this->usia} tahun";
40 | }
41 | }
42 |
43 | // Instansiasi objek
44 | $pengguna = new Pengguna();
45 |
46 | // Mengeset nilai properti tanggalLahir secara langsung
47 | // dengan format yang salah
48 | $pengguna->tanggalLahir = '1234-1234-1234'; // Fatal error: Uncaught Exception: Failed to parse time string (1234-1234-1234)
49 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/7_setter_dan_getter4.php:
--------------------------------------------------------------------------------
1 | tanggalLahir = $tanggalLahir;
21 |
22 | // Mengakses nilai properti tanggalLahir untuk menghitung usia
23 | $dateTimeTanggalLahir = new DateTime($this->tanggalLahir);
24 | $dateTimeHariIni = new DateTime();
25 | $hasilHitungUsia = $dateTimeHariIni->diff($dateTimeTanggalLahir)->y;
26 |
27 | // Mengeset properti usia dengan nilai dari variabel $hasilHitungUsia
28 | $this->usia = $hasilHitungUsia;
29 | }
30 |
31 | // Getter untuk properti tanggalLahir
32 | public function getTanggalLahir()
33 | {
34 | // Mengakses nilai properti tanggalLahir untuk DIKEMBALIKAN
35 | // dalam format penulisan tanggal Indonesia
36 | $dateTimeTanggalLahir = new DateTime($this->tanggalLahir);
37 | $formatterTanggal = new IntlDateFormatter('id_ID', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
38 | return $formatterTanggal->format($dateTimeTanggalLahir);
39 | }
40 |
41 | // Getter untuk properti usia
42 | public function getUsia()
43 | {
44 | // Mengakses nilai properti usia untuk diformat dan DIKEMBALIKAN
45 | return "{$this->usia} tahun";
46 | }
47 | }
48 |
49 | // Instansiasi objek
50 | $pengguna = new Pengguna();
51 |
52 | // Mengeset nilai properti tanggalLahir secara langsung
53 | // $pengguna->tanggalLahir = '1234-1234-1234'; // Fatal error: Uncaught Error: Cannot access private property Pengguna::$tanggalLahir
54 |
55 | // Mengeset nilai yang tidak sesuai format properti tanggalLahir melalui setter
56 | $pengguna->setTanggalLahir('1234-1234-1234'); // Eror Tertangani: Format tanggal salah
57 |
58 | // Menampilkan baris baru
59 | echo PHP_EOL;
60 |
61 | // Mengeset nilai yang sesuai format properti tanggalLahir melalui setter
62 | $pengguna->setTanggalLahir('2000-01-01');
63 |
64 | // Mengakses nilai properti tanggalLahir melalui getter untuk ditampilkan
65 | echo $pengguna->getTanggalLahir(); // 1 Januari 2000
66 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/7_setter_dan_getter6.php:
--------------------------------------------------------------------------------
1 | tanggalLahir = new DateTime($tanggalLahir);
24 | }
25 |
26 | private function getTanggalLahir()
27 | {
28 | $formatterTanggal = new IntlDateFormatter('id_ID', IntlDateFormatter::LONG, IntlDateFormatter::NONE);
29 | return $formatterTanggal->format($this->tanggalLahir);
30 | }
31 |
32 | private function getUsia()
33 | {
34 | $tanggalSekarang = new DateTime();
35 | $hasilHitungUsia = $tanggalSekarang->diff($this->tanggalLahir)->y;
36 |
37 | return "{$hasilHitungUsia} tahun";
38 | }
39 |
40 | public function __set($name, $value)
41 | {
42 | if ($name == 'tanggalLahir') {
43 | $this->setTanggalLahir($value);
44 |
45 | return;
46 | }
47 |
48 | echo '### Properti tidak ditemukan ###';
49 | }
50 |
51 | public function __get($name)
52 | {
53 | if ($name == 'tanggalLahir') {
54 | return $this->getTanggalLahir();
55 | }
56 |
57 | if ($name == 'usia') {
58 | return $this->getUsia();
59 | }
60 |
61 | echo '### Properti tidak ditemukan ###';
62 | }
63 | }
64 |
65 | // Instansiasi objek
66 | $pengguna = new Pengguna();
67 |
68 | // Mengeset properti tanggalLahir melalui setter ajaib
69 | $pengguna->tanggalLahir = '2000-01-01';
70 |
71 | // Mengakses nilai properti tanggalLahir
72 | // yang telah diformat melalui getter ajaib untuk ditampilkan
73 | echo $pengguna->tanggalLahir; // 1 Januari 2000
74 |
75 | // Mencetak baris baru
76 | echo PHP_EOL;
77 |
78 | // Mengakses nilai properti usia
79 | // yang telah diformat melalui getter ajaib untuk ditampilkan
80 | echo $pengguna->usia; // 23 tahun (2023)
81 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/8_method_chaining.php:
--------------------------------------------------------------------------------
1 | totalJamKerja = $totalHari * 8;
42 |
43 | return $this;
44 | }
45 |
46 | /**
47 | * Menghitung total jam lembur dan menyimpan hasilnya pada properti $totalJamLembur
48 | *
49 | * @param int $totalHari
50 | * @return Karyawan
51 | **/
52 | public function hitungLembur($totalHari)
53 | {
54 | $this->totalJamLembur = $totalHari * 1.5; // lembur diasumsikan 1.5 jam/hari
55 |
56 | return $this;
57 | }
58 |
59 | /**
60 | * Method untuk meng-assign potongan pada karyawan
61 | *
62 | * @param int $totalPotongan
63 | * @return Karyawan
64 | **/
65 | public function aturPotongan($totalPotongan)
66 | {
67 | $this->totalPotongan = $totalPotongan;
68 |
69 | return $this;
70 | }
71 |
72 | /**
73 | * Menghitung total gaji
74 | *
75 | * @return int
76 | **/
77 | public function hitungTotalGaji()
78 | {
79 | return ($this->totalJamKerja + $this->totalJamLembur) * $this->upahPerJam - $this->totalPotongan;
80 | }
81 | }
82 |
83 | $karyawan = new Karyawan();
84 |
85 | $total_gaji = $karyawan->hitungJamKerja(30)->hitungLembur(5)->aturPotongan(100000)->hitungTotalGaji();
86 |
87 | echo "Total gaji: Rp. $total_gaji";
88 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/8_method_chaining2.php:
--------------------------------------------------------------------------------
1 | totalJamKerja = $total_hari * 8;
41 | }
42 |
43 | /**
44 | * Menghitung total jam lembur dan menyimpan hasilnya pada properti $totalJamLembur
45 | *
46 | * @param int $totalHari
47 | **/
48 | public function hitungLembur($total_hari)
49 | {
50 | $this->totalJamLembur = $total_hari * 1;
51 | }
52 |
53 | /**
54 | * Method untuk meng-assign potongan pada karyawan
55 | *
56 | * @param int $totalPotongan
57 | **/
58 | public function aturPotongan($totalPotongan)
59 | {
60 | $this->totalPotongan = $totalPotongan;
61 | }
62 |
63 | /**
64 | * Menghitung total gaji
65 | *
66 | * @return int
67 | **/
68 | public function hitungTotalGaji()
69 | {
70 | return ($this->totalJamKerja + $this->totalJamLembur) * $this->upahPerJam - $this->totalPotongan;
71 | }
72 | }
73 |
74 | $karyawan = new Karyawan();
75 |
76 | $karyawan->hitungJamKerja(30);
77 | $karyawan->hitungLembur(5);
78 | $karyawan->aturPotongan(100000);
79 |
80 | $total_gaji = $karyawan->hitungTotalGaji();
81 |
82 | echo "Total gaji: Rp. $total_gaji";
83 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/8_method_chaining3.php:
--------------------------------------------------------------------------------
1 | jumlahIsiTeko += $jumlahAirMasuk;
20 | }
21 |
22 | /**
23 | * Menuang teko. Mengurangi isi teko.
24 | *
25 | * @param int $jumlahAirKeluar
26 | **/
27 | public function tuangAir($jumlahAirKeluar)
28 | {
29 | $this->jumlahIsiTeko -= $jumlahAirKeluar;
30 | }
31 |
32 | /**
33 | * Memeriksa isi teko.
34 | *
35 | **/
36 | public function periksaIsi()
37 | {
38 | echo "Jumlah air saat ini: {$this->jumlahIsiTeko} ml\n";
39 | }
40 | }
41 |
42 | $teko = new Teko();
43 |
44 | // Mengisi teko kosong
45 | $teko->isiTeko(1000);
46 |
47 | // Memeriksa isi teko
48 | $teko->periksaIsi();
49 | // Output:
50 | // Jumlah air saat ini: 1000 ml
51 |
52 | // Menuang air untuk seluruh anggota keluarga
53 | $teko->tuangAir(250);
54 | $teko->tuangAir(150);
55 | $teko->tuangAir(100);
56 | $teko->tuangAir(200);
57 | $teko->tuangAir(200);
58 |
59 | // Memeriksa isi teko
60 | $teko->periksaIsi();
61 | // Output:
62 | // Jumlah air saat ini: 100 ml
63 |
64 | // Menuang lagi untuk ayah
65 | $teko->tuangAir(100);
66 |
67 | // Memeriksa isi teko
68 | $teko->periksaIsi();
69 | // Output:
70 | // Jumlah air saat ini: 0 ml
71 |
72 | // Mengisi ulang teko yang kosong
73 | $teko->isiTeko(1000);
74 |
75 | // Memeriksa isi teko
76 | $teko->periksaIsi();
77 | // Output:
78 | // Jumlah air saat ini: 1000 ml
79 |
--------------------------------------------------------------------------------
/basics/14_oop_dasar/8_method_chaining4.php:
--------------------------------------------------------------------------------
1 | jumlahIsiTeko += $jumlahAirMasuk;
21 |
22 | return $this; // Untuk Method Chaining
23 | }
24 |
25 | /**
26 | * Menuang teko. Mengurangi isi teko.
27 | *
28 | * @param int $jumlahAirKeluar
29 | * @return Teko
30 | **/
31 | public function tuangAir($jumlahAirKeluar)
32 | {
33 | $this->jumlahIsiTeko -= $jumlahAirKeluar;
34 |
35 | return $this; // Untuk Method Chaining
36 | }
37 |
38 | /**
39 | * Memeriksa isi teko.
40 | *
41 | **/
42 | public function periksaIsi()
43 | {
44 | echo "Jumlah air saat ini: {$this->jumlahIsiTeko} ml\n";
45 | }
46 | }
47 |
48 | $teko = new Teko();
49 |
50 | // Mengisi teko kosong dan memeriksa isi teko
51 | $teko->isiTeko(1000)->periksaIsi();
52 | // Output:
53 | // Jumlah air saat ini: 1000 ml
54 |
55 | // Menuang air untuk seluruh anggota keluarga dan memeriksa isi teko
56 | $teko->tuangAir(250)
57 | ->tuangAir(150)
58 | ->tuangAir(100)
59 | ->tuangAir(200)
60 | ->tuangAir(200)
61 | ->periksaIsi();
62 | // Output:
63 | // Jumlah air saat ini: 100 ml
64 |
65 | // Menuang lagi untuk ayah dan memeriksa kembali isi teko
66 | $teko->tuangAir(100)->periksaIsi();
67 | // Output:
68 | // Jumlah air saat ini: 0 ml
69 |
70 | // Mengisi ulang teko yang kosong dan memeriksa isi teko
71 | $teko->isiTeko(1000)->periksaIsi();
72 | // Output:
73 | // Jumlah air saat ini: 1000 ml
74 |
--------------------------------------------------------------------------------
/basics/15_oop_lanjutan/1_inheritance_Hewan.php:
--------------------------------------------------------------------------------
1 | ";
6 |
7 | echo "Contoh Inheritance dalam PHP ";
8 |
9 | echo "class Hewan
10 | {
11 | // Deklarasi Properti
12 | public namaProperti = 'Properti Hewan';
13 | public informasiProperti = 25;
14 | protected jenis = 'Hewan';
15 | private privacy = 'Private';
16 |
17 | //Deklarasi Method
18 | public function perkenalan()
19 | {
20 | //Perintah Apa saja
21 | echo 'Ini merupakan method perkenalan'
22 | }
23 |
24 | public function salam()
25 | {
26 | //Perintah Apa saja
27 | echo 'Ini merupakan method salam '
28 | echo this->privacy;
29 | }
30 |
31 | final public function sapa()
32 | {
33 | //Perintah Apa saja
34 | echo 'Ini merupakan method salam '
35 | }
36 | }";
37 |
38 | class Hewan
39 | {
40 | // Deklarasi Properti
41 | public $namaProperti = 'Properti Hewan';
42 | public $informasiProperti = 25;
43 | protected $jenis = 'Hewan';
44 | private $privacy = 'Private';
45 |
46 | //Deklarasi Method
47 | public function perkenalan()
48 | {
49 | //Perintah Apa saja
50 | echo 'Ini merupakan method perkenalan';
51 | }
52 |
53 | public function salam()
54 | {
55 | //Perintah Apa saja
56 | echo 'Ini merupakan method salam ';
57 | echo $this->privacy;
58 | }
59 |
60 | final public function sapa()
61 | {
62 | //Perintah Apa saja
63 | echo 'Ini merupakan method salam ';
64 | }
65 | }
66 |
67 | echo " ";
68 | $pengguna = new Hewan();
69 | echo " ";
70 | echo "Hasil Salah satu method Pada Class Hewan",PHP_EOL;
71 | $pengguna->salam();
72 | echo " ";
73 | echo " ";
74 |
--------------------------------------------------------------------------------
/basics/15_oop_lanjutan/1_inheritance_Kucing.php:
--------------------------------------------------------------------------------
1 | ";
28 | echo " ";
29 | echo "Class Kucing merupakan turunan dari Class Hewan",PHP_EOL;
30 | echo " ";
31 | $kucing = new Kucing();
32 | echo "Hasil pemanggilan salah satu method class Hewan melalui class Kucing",PHP_EOL;
33 | $kucing->salam();
34 | echo " ";
35 | echo " ";
36 | echo "Hasil pemanggilan method bermain pada Class Kucing",PHP_EOL;
37 | $kucing->bermain();
38 |
39 | echo "";
40 |
--------------------------------------------------------------------------------
/basics/15_oop_lanjutan/2_object_type.php:
--------------------------------------------------------------------------------
1 | salam();
14 |
15 | echo 'Aku adalah seekor sapi';
16 | }
17 | }";
18 |
19 | class Sapi extends Hewan
20 | {
21 | // Method dengan objek sebagai parameternya
22 | public function bergerak(Hewan $animal)
23 | {
24 | // Memanggil method salam
25 | $animal->salam();
26 |
27 | echo ' Aku adalah seekor sapi';
28 | }
29 | }
30 |
31 | echo " ";
32 | echo " ";
33 | echo "Class Sapi merupakan turunan dari Class Hewan",PHP_EOL;
34 | echo " ";
35 | $sapi = new Sapi();
36 | $animal = new Hewan();
37 | echo "Hasil pemanggilan method dengan parameter object",PHP_EOL;
38 | $sapi->bergerak($animal);
39 |
40 | echo "";
41 |
--------------------------------------------------------------------------------
/basics/15_oop_lanjutan/3_access_modifier.php:
--------------------------------------------------------------------------------
1 | ";
8 |
9 | echo "class Tumbuhan
10 | {
11 | // Private Property
12 | protected nama = 'Tumbuhan';
13 |
14 | // Method Public
15 | public function bergerak()
16 | {
17 | echo 'Aku adalah Class Tumbuhan';
18 | }
19 | }";
20 |
21 | class Tumbuhan
22 | {
23 | // Private Property
24 | protected $nama = 'Tumbuhan';
25 |
26 | // Method Public
27 | public function bergerak()
28 | {
29 | echo 'Aku adalah Class Tumbuhan ';
30 | echo $this->nama;
31 | }
32 | }
33 |
34 | echo " ";
35 | echo " ";
36 | echo "Class Kucing merupakan turunan dari Class Hewan",PHP_EOL;
37 | echo " ";
38 | $kucing = new Kucing();
39 | echo "Memanggil Properti Public dari Class Hewan",PHP_EOL;
40 | var_dump($kucing->namaProperti);
41 |
42 | echo " ";
43 | echo " ";
44 | echo "Class Tunbuhan merupakan Class yang Berdiri Sendiri",PHP_EOL;
45 | echo " ";
46 | $tumbuhan = new Tumbuhan();
47 | echo "Memanggil Method dari Class Tumbuhan",PHP_EOL;
48 | $tumbuhan->bergerak();
49 |
50 | echo "";
51 |
--------------------------------------------------------------------------------
/basics/15_oop_lanjutan/4_overriding_and_final.php:
--------------------------------------------------------------------------------
1 | ";
8 |
9 | echo "class Ayam extends Hewan
10 | {
11 | // Overriding salam
12 | public function salam()
13 | {
14 | echo 'Overriding Method salam';
15 | }
16 | }";
17 |
18 | class Ayam extends Hewan
19 | {
20 | // Overriding salam
21 | public function salam()
22 | {
23 | echo 'Overriding Method salam';
24 | }
25 | }
26 |
27 | echo " ";
28 | echo " ";
29 | echo "Class Ayam merupakan turunan dari Class Hewan",PHP_EOL;
30 | echo " ";
31 | $kucing = new Ayam();
32 | echo "Memanggil method salam yang telah di override",PHP_EOL;
33 | $kucing->salam();
34 |
35 | echo "";
36 |
--------------------------------------------------------------------------------
/basics/1_hello_world/2_hello_world.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Document
8 |
9 |
10 |
11 | Ini adalah text yang di cetak oleh php =
12 |
15 |
16 | = "Teks ini juga dari PHP" ?>
17 |
24 |
25 |
--------------------------------------------------------------------------------
/basics/2_variable_datatype/2_variable_in_string.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | /**
6 | * Variabel Dalam String
7 | * --------------------------
8 | */
9 | echo "Variabel Dalam String ";
10 |
11 | // -------------------------
12 | echo "Menulis variabel dalam string dengan petik satu. ";
13 | // Contoh 1:
14 | $name = 'Feri Irawan';
15 | $text = 'Halo' . $name;
16 | // ↑
17 | // Tanpa spasi
18 |
19 | echo $text; // Hasil: HaloFeri Irawan
20 | echo "\n";
21 |
22 | // Contoh 2:
23 | $name = 'Feri Irawan';
24 | $text = 'Halo ' . $name . ', apa kabar?';
25 | // ↑
26 | // Dengan spasi
27 |
28 | echo $text; // Hasil: Halo Feri Irawan, apa kabar?
29 | echo "\n";
30 |
31 | // --------------------------
32 | echo "Menulis variabel dalam string dengan petik dua. ";
33 | // Contoh 1:
34 | $name = 'Feri Irawan';
35 | $text = "Halo$name";
36 | // ↑
37 | // Tanpa spasi
38 |
39 | echo $text; // Hasil: HaloFeri Irawan
40 | echo "\n";
41 |
42 | // Contoh 2:
43 | $name = 'Feri Irawan';
44 | $text = "Halo $name apa kabar?";
45 | // ↑ ↑
46 | // Dengan spasi
47 |
48 | echo $text; // Hasil: Halo Feri Irawan, apa kabar?
49 | echo "\n";
50 |
51 | // Contoh 3:
52 | $username = 'contoh';
53 | $email = 'gmail.com';
54 | $text = "{$username}{$email}";
55 |
56 | echo $text; // Hasil: contoh@gmail.com
57 | echo "\n";
58 |
59 | // Contoh 4:
60 | $username = 'contoh';
61 | $email = 'gmail.com';
62 | $text = "$username$email";
63 |
64 | echo $text; // Hasil: contoh@gmail.com
65 | echo "\n";
66 |
67 | // --------------------------
68 | echo "Menulis variabel dalam string dengan sintaks heredoc. ";
69 | // Contoh 1:
70 | $name = 'Feri Irawan';
71 | $umur = 17;
72 |
73 | $text = <<";
101 |
--------------------------------------------------------------------------------
/basics/2_variable_datatype/4_constant_variable.php:
--------------------------------------------------------------------------------
1 | ";
4 |
5 | /**
6 | * Konstanta
7 | * --------------------------
8 | */
9 | echo "Konstanta ";
10 |
11 | // --------------------------
12 | echo "Penulisan konstanta yang diperbolehkan ";
13 | // Contoh:
14 | define('NAMA', "Feri Irawan");
15 | define('NAMA_NEGARA', "Indonesia"); // menggunakan underscore
16 | define('MOBIL01', "Indonesia"); // menggunakan angka di akhir
17 | define("__NAMA__", "Wahyudi"); // menggunakan double underscore diawal dan akhir
18 |
19 | echo NAMA . "\n"; // Hasil: Feri Irawan
20 | echo NAMA_NEGARA . "\n"; // Hasil: Indonesia
21 | echo __NAMA__ . "\n"; // Hasil: Wahyudi
22 |
23 |
24 | // --------------------------
25 | // Penulisan yang tidak diperbolehkan
26 | // Contoh:
27 | define('01NAMA', "Badar Wildanie");
28 | define('MEREK-MOBIL', "Honda");
29 |
30 |
31 | // --------------------------
32 | echo "Penulisan konstanta dengan kata kunci const ";
33 | /*
34 | * Deklarasi variabel konstanta dengan kata kunci const
35 | * const NAMA_VARIABEL = "nilai variabel"
36 | * nilai variabel dapat berupa string, number, null, dan boolean
37 | */
38 |
39 | // Contoh:
40 | // Deklarasi Variabel
41 | const NAMA_LENGKAP = "Rochmad Nurul Fahmi";
42 |
43 | // Menampilkan nilai
44 | echo NAMA_LENGKAP . "\n"; // Hasil: Rochmad Nurul Fahmi
45 | // Atau
46 | echo constant("NAMA_LENGKAP"); // Hasil: Rochmad Nurul Fahmi
47 |
48 | echo "";
49 |
--------------------------------------------------------------------------------
/basics/3_operator/1_aritmatika_operator.php:
--------------------------------------------------------------------------------
1 | " . $a += $b;
20 | echo "\n \$a -= \$b => " . $a -= $b;
21 | echo "\n \$a *= \$b => " . $a *= $b;
22 | echo "\n \$a /= \$b => " . $a /= $b;
23 | echo "\n \$a %= \$b => " . $a %= $b;
24 |
25 | /**
26 | * Contoh Bitwise Assignment Operator
27 | */
28 | echo "\n Bitwise Assignment Operator";
29 | echo "\n \$a &= \$b => " . $a &= $b;
30 | echo "\n \$a |= \$b => " . $a |= $b;
31 | echo "\n \$a ^= \$b => " . $a ^= $b;
32 | echo "\n \$a <<= \$b => " . $a <<= $b;
33 | echo "\n \$a >>= \$b => " . $a >>= $b;
34 |
35 | /**
36 | * Contoh Operator Assignment Lainnya
37 | */
38 | $a = "satu";
39 | $b = "dua";
40 | $c = null;
41 |
42 | echo "\n String Assignment Operator";
43 | echo "\n" . $a .= " " . $b;
44 |
45 | echo "\n Null Coalesce Operator";
46 | $d = $c ?? $b;
47 | echo "\n" . $d;
48 |
--------------------------------------------------------------------------------
/basics/3_operator/3_comparison_operator.php:
--------------------------------------------------------------------------------
1 | $b); // false
28 |
29 | // Lebih kecil dari
30 | echo var_dump($a < $b); // true
31 |
32 | // Lebih besar dari atau sama dengan
33 | echo var_dump($a >= $b); // false
34 |
35 | // Lebih kecil dari atau sama dengan
36 | echo var_dump($a <= $b); // true
37 |
38 | // Spaceship
39 | echo var_dump($a <=> $b); // -1
40 |
--------------------------------------------------------------------------------
/basics/3_operator/4_logical_operator.php:
--------------------------------------------------------------------------------
1 | 'nila', 'b' => 'gurame');
4 | $b = array('a' => 'bawal', 'b' => 'lele', 'c' => 'bucuk');
5 |
6 | // Union $a dan $b
7 | $c = $a + $b; //Union
8 | echo "Union dari \$a dan \$b: \n";
9 | var_dump($c); //dump result
10 |
11 | // Union $b dan $a
12 | $c = $b + $a; //Union
13 | echo "Union dari \$b dan \$a: \n";
14 | var_dump($c); //dump result
15 |
16 | // Union $a += $b (Assignment Operator)
17 | $a += $b; //Union
18 | echo "Union dari \$a += \$b: \n";
19 | var_dump($a); //dump result
20 |
21 | /** comparison
22 | *
23 | * @var $c $d as Array
24 | * @return Array
25 | */
26 | $c = array("apel", "mangga");
27 | $d = array(1 => "mangga", "0" => "apel");
28 |
29 | var_dump($c == $d); // Equality
30 | var_dump($c === $d); // Identity
31 |
--------------------------------------------------------------------------------
/basics/3_operator/null_coalesce.php:
--------------------------------------------------------------------------------
1 | null,
5 | 'kota' => 'padang'
6 | ];
7 | if (isset($data['name'])) {
8 | $name = $data['name'];
9 | } else {
10 | $name = "kondiak";
11 | }
12 |
13 | var_dump($name . "\n");
14 |
15 | $name = $data['name'] ?? "kondiak";
16 | var_dump($name . "\n");
17 |
--------------------------------------------------------------------------------
/basics/4_conditional_statements/3_operator_ternary.php:
--------------------------------------------------------------------------------
1 | 75 ? "Lulus KKM !" : "Tidak lulus KKM !";
20 |
--------------------------------------------------------------------------------
/basics/4_conditional_statements/4_ternary_assignment.php:
--------------------------------------------------------------------------------
1 | 75) menghasilkan true
18 | $isLulus = $nilai_ujian > 75 ? true : false;
19 |
20 | // Mencetak string "Lulus KKM !" jika $isLulus bernilai true
21 | // Mencetak string "Tidak lulus KKM !" jika $isLulus tidak bernilai true
22 | echo $isLulus ? "Lulus KKM !" : "Tidak lulus KKM !";
23 |
--------------------------------------------------------------------------------
/basics/4_conditional_statements/5_ternary_shorthand.php:
--------------------------------------------------------------------------------
1 | 75 ?: false;
20 |
21 | // Mencetak string "Lulus KKM !" jika $isLulus bernilai true
22 | // Mencetak string "Tidak lulus KKM !" jika $isLulus tidak bernilai true
23 | echo $isLulus ? "Lulus KKM !" : "Tidak lulus KKM !";
24 |
--------------------------------------------------------------------------------
/basics/5_perulangan/1_for.php:
--------------------------------------------------------------------------------
1 | ';
4 | echo 'Perulangan PHP ';
5 | echo'1.Menggunakan For ';
6 | echo'';
7 | //======================Teknik Sederhana Perulangan For ==========================
8 | //Teknik Basic
9 | echo'Teknik Dasar ';
10 |
11 | echo'- Ascending 1-5';
12 | //====================================
13 | // Logic : Pertama melakukan Pendeklarasi i dengan nilai awal 1,
14 | // Lalu Kondisi Jika i dibawah 5 maka i nambah 1 tiap perulangan
15 | for ($i = 1; $i <= 5; $i++) {
16 | echo 'Perulangan ' . $i . '';
17 | }
18 | //====================================
19 |
20 |
21 | echo'- Descending 5-1';
22 | //====================================
23 | //Logic :Pertama melakukan Pendeklarasi i dengan nilai awal 5, Lalu Kondisi Jika i atas, 5 maka i kurang 1 tiap perulangan
24 | for ($i = 5; $i >= 1; $i--) {
25 | echo 'Perulangan ' . $i . '';
26 | }
27 |
28 |
29 | echo'- Nested Loop';
30 | //====================================
31 | for ($i = 1; $i <= 5; $i++) {
32 | for ($j = 1; $j <= $i; $j++) {
33 | echo '*';
34 | }
35 | echo '';
36 | }
37 | //==============================================================================
38 | echo '';
39 |
--------------------------------------------------------------------------------
/basics/5_perulangan/2_foreach.php:
--------------------------------------------------------------------------------
1 | ';
4 | echo 'Perulangan PHP ';
5 | echo'2.Menggunakan Foreach ';
6 | echo'';
7 | //======================Teknik Sederhana Perulangan Foreach ==========================
8 | //Teknik Basic
9 | $colors = array("red", "green", "blue", "yellow");
10 |
11 | foreach ($colors as $value) {
12 | echo "$value ";
13 | }
14 |
15 | //==============================================================================
16 | echo '';
17 |
--------------------------------------------------------------------------------
/basics/5_perulangan/3_while.php:
--------------------------------------------------------------------------------
1 | ";
8 | $x++;
9 | }
10 | " ";
11 | $y = 5;
12 | //disimpulkan bahwa nilai y = 5, karena nilai y lebih kecil dari 1 maka kondisi tersebut bernilai false, maka code selanjutnya tidak di eksikusi.
13 | while ($y <= 1) {
14 | echo "Nilai Y: $y ";
15 | $y++;
16 | }
17 |
--------------------------------------------------------------------------------
/basics/5_perulangan/4_do_while.php:
--------------------------------------------------------------------------------
1 | ';
4 | echo 'Perulangan PHP ';
5 | echo'1.Menggunakan For ';
6 | echo'';
7 | //======================Teknik Sederhana Perulangan For ==========================
8 | //Teknik Basic
9 | echo'Teknik Dasar ';
10 |
11 | echo'- Ascending 1-5';
12 | //====================================
13 | //Logic : Pertama melakukan Pendeklarasi i dengan nilai awal 1, Lalu Kondisi Jika i dibawah 5 maka i nambah 1 tiap perulangan
14 | $i = 1;
15 | do {
16 | echo 'Perulangan ' . $i . '';
17 | $i++;
18 | } while ($i <= 5);
19 | //====================================
20 |
21 |
22 | echo'- Descending 5-1';
23 | //====================================
24 | //Logic :Pertama melakukan Pendeklarasi i dengan nilai awal 5, Lalu Kondisi Jika i atas, 5 maka i kurang 1 tiap perulangan
25 | $i = 5;
26 | do {
27 | echo 'Perulangan ' . $i . '';
28 | $i--;
29 | } while ($i >= 1);
30 |
31 |
32 | echo'- Nested Loop';
33 | //====================================
34 |
35 | $i = 1;
36 | do {
37 | $j = 1;
38 | do {
39 | echo '*';
40 | $j++;
41 | } while ($j <= $i);
42 | echo '';
43 | $i++;
44 | } while ($i <= 5);
45 | //==============================================================================
46 | echo '';
47 |
--------------------------------------------------------------------------------
/basics/6_manipulasi_string/1_properti_string.php:
--------------------------------------------------------------------------------
1 | ';
4 |
5 | // ---------------------------------------------------------------------------
6 | echo 'Mengambil properti string ';
7 | // ---------------------------------------------------------------------------
8 | echo ' ';
9 | echo "Menghitung Banyaknya karakter ";
10 |
11 | $text = "Ini adalah contoh teks yang saya buat";
12 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
13 | echo 'Jumlah karakter: ' . strlen($text), PHP_EOL; // Output: 37
14 |
15 | // ---------------------------------------------------------------------------
16 | echo ' ';
17 | echo "Menghitung Banyaknya kata ";
18 |
19 | $text = "Ini adalah contoh teks yang saya buat";
20 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
21 | echo 'Jumlah kata: ' . str_word_count($text), PHP_EOL; // Output: 7
22 |
23 | // ---------------------------------------------------------------------------
24 | echo ' ';
25 | echo "Mencari posisi dari sebuah kata ";
26 |
27 | $text = "Ini adalah contoh teks yang saya buat";
28 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
29 | echo "Posisi kata 'contoh': " . strpos($text, 'contoh'), PHP_EOL; // Output: 11
30 |
31 | // ---------------------------------------------------------------------------
32 | echo ' ';
33 | echo "Menghitung banyaknya kata tertentu ";
34 |
35 | $text = "ini adalah ini contoh teks yang saya buat";
36 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
37 | echo "Jumlah kata 'ini': " . substr_count($text, 'ini'), PHP_EOL; // Output: 2
38 |
39 | echo '';
40 |
--------------------------------------------------------------------------------
/basics/6_manipulasi_string/2_pemotongan_string.php:
--------------------------------------------------------------------------------
1 | ';
4 |
5 | // ---------------------------------------------------------------------------
6 | echo 'Memotong string ';
7 | // ---------------------------------------------------------------------------
8 |
9 |
10 | // ---------------------------------------------------------------------------
11 | echo "Memotong dari kiri, kanan dan keduanya ";
12 |
13 | $text = "ini adalah contoh teks yang saya buat";
14 | echo 'Contoh Tulisan: ' . $text . ' ', PHP_EOL;
15 | echo 'memotong dari kiri yang mengandung karakter `inibuat` (ltrim): ' . ltrim($text, 'inibuat'), PHP_EOL;
16 | echo 'memotong dari kanan yang mengandung karakter `inibuat` (rtrim): ' . rtrim($text, 'inibuat'), PHP_EOL;
17 | echo 'memotong dari kiri dan kanan yang mengandung karakter `inibuat` (trim): ' . trim($text, 'inibuat'), PHP_EOL;
18 |
19 | echo '';
20 |
--------------------------------------------------------------------------------
/basics/6_manipulasi_string/3_kapitalisasi_string.php:
--------------------------------------------------------------------------------
1 | ';
4 |
5 | // ---------------------------------------------------------------------------
6 | echo 'Kapitalisasi String ';
7 | // ---------------------------------------------------------------------------
8 | echo ' ';
9 | echo "Mengubah karakter menjadi huruf kecil ";
10 |
11 | $text = "Ini Adalah coNtoh teKs yAng Saya Buat";
12 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
13 | echo 'Hasilnya: ' . strtolower($text), PHP_EOL; // Output: ini adalah contoh teks yang saya buat
14 |
15 | // ---------------------------------------------------------------------------
16 | echo ' ';
17 | echo "Mengubah karakter menjadi huruf besar ";
18 |
19 | $text = "Ini Adalah coNtoh teKs yAng Saya Buat";
20 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
21 | echo 'Hasilnya: ' . strtoupper($text), PHP_EOL; // Output: INI ADALAH CONTOH TEKS YANG SAYA BUAT
22 |
23 | // ---------------------------------------------------------------------------
24 | echo ' ';
25 | echo "Mengubah karakter pertama menjadi huruf besar ";
26 |
27 | $text = "ini adalah contoh teks yang saya buat";
28 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
29 | echo 'Hasilnya: ' . ucfirst($text), PHP_EOL; // Output: Ini adalah contoh teks yang saya buat
30 |
31 | // ---------------------------------------------------------------------------
32 | echo ' ';
33 | echo "Mengubah karakter pertama setiap kata menjadi huruf besar ";
34 |
35 | $text = "ini adalah contoh teks yang saya buat";
36 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
37 | echo 'Hasilnya: ' . ucwords($text), PHP_EOL; // Output: Ini Adalah Contoh Teks Yang Saya Buat
38 |
39 | // ---------------------------------------------------------------------------
40 | echo ' ';
41 | echo "Mengubah karakter pertama menjadi huruf kecil ";
42 |
43 | $text = "INI ADALAH CONTOH TEKS YANG SAYA BUAT";
44 | echo 'Contoh Tulisan: ' . $text, PHP_EOL;
45 | echo 'Hasilnya: ' . lcfirst($text), PHP_EOL; // Output: iNI ADALAH CONTOH TEKS YANG SAYA BUAT
46 |
47 | // ---------------------------------------------------------------------------
48 |
--------------------------------------------------------------------------------
/basics/6_manipulasi_string/5_escape_dan_formatting.php:
--------------------------------------------------------------------------------
1 | ';
4 |
5 |
6 | echo " Menambah slash dalam string ";
7 | echo " ";
8 |
9 | echo " addslashes() ";
10 |
11 |
12 | echo "Text sebelum menggunakan addslashes():",PHP_EOL;
13 | $text = '-Ayo belajar di bellshade';
14 | echo "$text";
15 | // -------------------------------------------
16 | echo " ";
17 |
18 | echo "Text sesudah menggunakan addslashes(): ",PHP_EOL;
19 | $text1 = addslashes('-Ayo belajar di "bellshade"');
20 | echo "$text1";
21 |
22 | echo "Contoh lagi ";
23 | echo "Text sebelum menggunakan addslashes():",PHP_EOL;
24 | echo "$text";
25 | // ---------------------------------------------------
26 | echo " ";
27 |
28 | echo "Text sesudah menggunakan addslashes(): ",PHP_EOL;
29 | $text2 = addslashes("-Ayo belajar di 'bellshade'");
30 | echo "$text2";
31 | //---------------------------------------------------
32 | echo " ";
33 | echo "------------------------------------------------", PHP_EOL;
34 |
35 | echo "Text sebelum menggunakan addslashes():",PHP_EOL;
36 | echo "$text";
37 | //---------------------------------------------------
38 | echo " ";
39 |
40 | echo "Text sesudah menggunakan addslashes(): ",PHP_EOL;
41 | $text3 = addslashes("-Ayo belajar di \bellshade\ ");
42 | echo "$text3";
43 | //---------------------------------------------------
44 | echo " ";
45 |
46 | echo " stripslashes() ";
47 |
48 | // ---------------
49 | echo "Sebelum menggunakan stripslashes(): ", PHP_EOL;
50 | $text = "Ayo belajar \ di bellshade";
51 | echo $text, PHP_EOL;
52 | // Output
53 | // Ayo belajar \ di bellshade
54 | echo " ";
55 | //-----------------
56 | echo "Sesudah menggunakan stripslashes(): ", PHP_EOL;
57 | $text = "Sandi:\"Hai, apa kabar semuanya?\"";
58 | $text1 = stripslashes($text);
59 | echo $text1, PHP_EOL;
60 | // Output
61 | // Sandi:"Hai, apa kabar semuanya?"
62 |
63 | echo " ";
64 | echo '';
65 |
--------------------------------------------------------------------------------
/basics/6_manipulasi_string/6_manipulasi_string.php:
--------------------------------------------------------------------------------
1 | ";
4 | // ----------------
5 | echo "Manipulasi String ";
6 | echo " ";
7 |
8 | echo "str_pad() ";
9 | // ---------------
10 | echo "Text sebelum menggunakan str_pad():",PHP_EOL;
11 | $text = 'Manipulasi String';
12 | echo $text;
13 | // -------------------------------------------
14 | echo " ";
15 |
16 | echo "Text sesudah menggunakan str_pad(): ",PHP_EOL;
17 | $text1 = str_pad('Manipulasi String', 20, ".");
18 | echo $text1;
19 |
20 | echo "wordwrap() ";
21 | // ---------------
22 | echo "Text sebelum menggunakan wordwrap():",PHP_EOL;
23 | $text = 'Manipulasi String';
24 | echo $text;
25 | // -------------------------------------------
26 | echo " ";
27 |
28 | echo "Text sesudah menggunakan wordwrap(): ",PHP_EOL;
29 | $text1 = wordwrap('Manipulasi String', 5);
30 | echo $text1;
31 |
32 | echo "str_shuffle() ";
33 | // ---------------
34 | echo "Text sebelum menggunakan str_shuffle():",PHP_EOL;
35 | $text = 'Manipulasi String';
36 | echo $text;
37 | // -------------------------------------------
38 | echo " ";
39 |
40 | echo "Text sesudah menggunakan str_shuffle(): ",PHP_EOL;
41 | $text1 = str_shuffle('Manipulasi String');
42 | echo $text1;
43 |
44 | echo "str_repeat() ";
45 | // ---------------
46 | echo "Text sebelum menggunakan str_repeat():",PHP_EOL;
47 | $text = 'Manipulasi String';
48 | echo $text;
49 | // -------------------------------------------
50 | echo " ";
51 |
52 | echo "Text sesudah menggunakan str_repeat(): ",PHP_EOL;
53 | $text1 = str_repeat('Manipulasi String', 10);
54 | echo $text1;
55 |
56 | echo "str_replace() ";
57 | // ---------------
58 | echo "Text sebelum menggunakan str_replace():",PHP_EOL;
59 | $text = 'Manipulasi String';
60 | echo $text;
61 | // -------------------------------------------
62 | echo " ";
63 |
64 | echo "Text sesudah menggunakan str_replace(): ",PHP_EOL;
65 | $text1 = str_replace('Manipulasi', 'Mencoba', 'Manipulasi String');
66 | echo $text1;
67 |
68 | echo "strtr() ";
69 | // ---------------
70 | echo "Text sebelum menggunakan strtr():",PHP_EOL;
71 | $text = 'Manipulasi String';
72 | echo $text;
73 | // -------------------------------------------
74 | echo " ";
75 |
76 | echo "Text sesudah menggunakan strtr(): ",PHP_EOL;
77 | $text1 = strtr('Manipulasi String', 'ia', 'eo');
78 | echo $text1;
79 |
80 | echo "";
81 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/1_array.php:
--------------------------------------------------------------------------------
1 | ';
19 | echo 'membuat array dengan perintah : ';
20 | echo '$kota1 = array(\'Padang\', \'Batu Sangkar\', \'Paya Kumbuh\', \'Pariaman\', \'Solok\');
';
21 | echo ' Hasil dari $kota1: ';
22 | print_r($kota1);
23 |
24 | echo ' Membuat Array dengan perintah : ';
25 | echo '$kota2 = [\'Padang\', \'Batu Sangkar\', \'Paya Kumbuh\', \'Pariaman\', \'Solok\'];
';
26 | echo ' Hasil dari $kota2: ';
27 | print_r($kota2);
28 |
29 | /** Mengakses Elemen Array */
30 | echo ' Mengakses Elemen Array : ';
31 | echo 'Syntax : $kota2[0
];
';
32 | echo 'hasil : ';
33 |
34 | echo $kota2[0]; //Perintah Untuk Mengakses Elemen Pertama (Index 0)
35 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/2_jenis_array.php:
--------------------------------------------------------------------------------
1 | 'satu', 'dua', 'tiga', 'empat', 'lima']; //Membuat Array Manual(Index)
16 |
17 | /** Tampilkan Hasil */
18 | echo '';
19 | echo 'Array Index : ';
20 | print_r($index1);
21 | echo ' ';
22 | print_r($index2);
23 |
24 | /** Asosiatif Array */
25 | $asos = ['origin' => 'bellshade', 'repo' => 'php', 'branch' => 'main']; //Membuat Array Key String (Asosiatif Array)
26 |
27 | /** Tampilkan hasil */
28 | echo ' Array Asosiatif : ';
29 | print_r($asos);
30 |
31 | /** Gabungan Index dan Asosiatif Array */
32 | $gab = [
33 | 1,
34 | 2,
35 | 3,
36 | 'origin' => 'bellshade',
37 | 8 => 4,
38 | 0 => 5,
39 | 6,
40 | 'repo' => 'php',
41 | 'branch' => 'main'
42 | ];
43 |
44 | echo ' Gabungan Index dan Asositif Array : ';
45 | print_r($gab);
46 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/3_1_array_multidimensi.php:
--------------------------------------------------------------------------------
1 | 'satu', 1 => 'dua', 2 => ['tiga', 'three'], 3 => ['empat', 'four']];
14 | $dua_dimensi2 = [
15 | 'sayur' => ['bayam', 'kangkung', 'sawi'],
16 | 'buah' => ['mangga', 'pepaya', 'semangka']
17 | ];
18 |
19 | /** Array Tiga Dimensi dan seterusnya */
20 | $hewan = [
21 | 'darat' => [
22 | 'peliharaan' => ['kucing', 'anjing'],
23 | 'ternak' => [
24 | 'berkaki dua' => ['ayam', 'itik', 'angsa'],
25 | 'berkaki empat' => ['sapi', 'kambing', 'kerbau']
26 | ],
27 | ],
28 | 'air' => [
29 | 'air asin' => ['ikan', 'penyu', 'gurita'],
30 | 'air tawar' => ['ikan air tawar', 'belut']
31 | ],
32 | 'udara' => 'burung'
33 | ];
34 |
35 | /** Tampilkan Hasil */
36 | echo '';
37 | echo 'Array Multi Dimensi ';
38 | echo 'Linear atau Satu Dimensi ';
39 | print_r($satu_dimensi);
40 |
41 | echo 'Array Dua Dimensi ';
42 | print_r($dua_dimensi1);
43 | print_r($dua_dimensi2);
44 |
45 | echo 'Array Tiga Dimensi dan Lebih ';
46 | print_r($hewan);
47 | print_r([$satu_dimensi, $dua_dimensi2, $hewan]);
48 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/3_2_implementasi_table_array.php:
--------------------------------------------------------------------------------
1 | ['username' => 'wildanie12', 'nama' => 'Badar Wildani', 'status' => ['Member', 'Owner']], //Baris pertama dari tabel
13 | 2 => ['username' => 'mhaikalla', 'nama' => 'M Haikal Anatam', 'status' => ['Member', 'Contributor']], //Baris kedua dari tabel
14 | 3 => ['username' => 'adhywiranto44', 'nama' => 'Adhy Wiranto', 'status' => ['Member', 'Admin']], //Baris ketiga dari tabel
15 | 4 => ['username' => 'nomadkode', 'nama' => 'Ramset', 'status' => ['Member', 'Admin']], //Baris keempat dari tabel
16 | 5 => ['username' => 'kondiak', 'nama' => 'Ricky Hadinata', 'status' => 'contributor'] //Baris kelima dari tabel
17 | ];
18 |
19 | /** Tampilkan Array */
20 | echo '';
21 | print_r($tabelcontoh);
22 | echo ' ';
23 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_diff.php:
--------------------------------------------------------------------------------
1 | $myHobies = ' . json_encode($myHobies) . ' ';
7 | echo '$yourHobies = ' . json_encode($yourHobies) . ' ';
8 |
9 | echo 'Hasil array_diff
: ' . json_encode(array_diff($myHobies, $yourHobies));
10 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_flip.php:
--------------------------------------------------------------------------------
1 | 'dota 2',
5 | 'selasa' => 'apex',
6 | 'rabu' => 'pokemon unite',
7 | ];
8 |
9 | $fliped = array_flip($arr);
10 |
11 | echo 'Hasil flip : ' . json_encode($fliped) . ' ';
12 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_keys.php:
--------------------------------------------------------------------------------
1 | 'toyota',
5 | 'germany' => 'bmw',
6 | ];
7 |
8 | echo '';
9 | print_r($cars);
10 | echo ' ';
11 |
12 | echo 'array_keys($cars) : ';
13 | print_r(array_keys($cars));
14 |
15 | echo ' array_keys($cars, \'bmw\') : ';
16 | print_r(array_keys($cars, 'bmw'));
17 |
18 | echo ' array_keys($cars, \'bmw\', true) : ';
19 | print_r(array_keys($cars, 'bmw', true));
20 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_merge.php:
--------------------------------------------------------------------------------
1 | Hasil merge : ' . json_encode($merged) . ' ';
9 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_pop.php:
--------------------------------------------------------------------------------
1 | ';
6 | print_r($cars);
7 | echo '';
8 |
9 | echo 'Element yang dikeluarkan : ' . array_pop($cars);
10 |
11 | echo ' Sisa array : ';
12 | print_r($cars);
13 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_push.php:
--------------------------------------------------------------------------------
1 | Array $games = ' . json_encode($games) . '';
6 |
7 | echo 'Hasil dari array_rand($games) : ' . json_encode(array_rand($games)) . ' ';
8 | echo 'Hasil dari array_rand($games, 2) : ' . json_encode(array_rand($games, 2)) . ' ';
9 |
10 | echo 'Acak ulang ';
11 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_reverse.php:
--------------------------------------------------------------------------------
1 | Hasil reverse : ' . json_encode($reversed) . '';
8 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_shift.php:
--------------------------------------------------------------------------------
1 | ';
6 | print_r($cars);
7 | echo '';
8 |
9 | echo 'Element yang dikeluarkan : ' . array_shift($cars);
10 |
11 | echo ' Sisa array : ';
12 | print_r($cars);
13 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_slice.php:
--------------------------------------------------------------------------------
1 | Hasil array_slice($fruits, 1) :' . json_encode(array_slice($fruits, 1)) . '';
6 | echo 'Hasil array_slice($fruits, 1, 2) :' . json_encode(array_slice($fruits, 1, 2)) . ' ';
7 | echo 'Hasil array_slice($fruits, 1, 2, true) :' . json_encode(array_slice($fruits, 1, 2, true)) . ' ';
8 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_splice.php:
--------------------------------------------------------------------------------
1 | $arr1 = ' . json_encode($arr1) . '';
6 | echo 'Hasil array_splice($arr1, 2) : ' . json_encode(array_splice($arr1, 2)) . ' ';
7 | echo '$arr1 = ' . json_encode($arr1) . ' ';
8 |
9 | echo ' ';
10 |
11 | $arr2 = ['a', 'b', 'c', 'd'];
12 |
13 | echo '$arr2 = ' . json_encode($arr2) . ' ';
14 | echo 'Hasil array_splice($arr2, 2, 1) : ' . json_encode(array_splice($arr2, 2, 1)) . ' ';
15 | echo '$arr2 = ' . json_encode($arr2) . ' ';
16 |
17 | echo ' ';
18 |
19 | $arr3 = ['a', 'b', 'c', 'd'];
20 |
21 | echo '$arr3 = ' . json_encode($arr3) . ' ';
22 | echo 'Hasil array_splice($arr3, 2, 1, [\'e\']) : ' . json_encode(array_splice($arr3, 2, 1, ['e'])) . ' ';
23 | echo '$arr3 = ' . json_encode($arr3) . ' ';
24 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_array_unshift.php:
--------------------------------------------------------------------------------
1 | 'toyota',
5 | 'germany' => 'bmw',
6 | ];
7 |
8 | echo '';
9 | print_r($cars);
10 | echo ' ';
11 |
12 | echo 'array_values($cars) : ';
13 | print_r(array_values($cars));
14 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_arsort.php:
--------------------------------------------------------------------------------
1 | 'orange',
5 | 'b' => 'manggo',
6 | 'c' => 'grape',
7 | ];
8 |
9 | arsort($fruits);
10 | echo 'Hasil arsort($fruits) :' . json_encode($fruits) . ' ';
11 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_asort.php:
--------------------------------------------------------------------------------
1 | 'orange',
5 | 'b' => 'manggo',
6 | 'c' => 'grape',
7 | ];
8 |
9 | asort($fruits);
10 | echo 'Hasil asort($fruits) :' . json_encode($fruits) . ' ';
11 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_count.php:
--------------------------------------------------------------------------------
1 | ' . print_r($array, true) . '';
9 |
10 | echo 'count($array) :' . count($array) . ' ';
11 | echo 'count($array, COUNT_RECURSIVE) :' . count($array, COUNT_RECURSIVE);
12 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_krsort.php:
--------------------------------------------------------------------------------
1 | 'orange',
5 | 'c' => 'grape',
6 | 'b' => 'manggo',
7 | ];
8 |
9 | krsort($fruits);
10 | echo 'Hasil krsort($fruits) :' . json_encode($fruits) . ' ';
11 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_ksort.php:
--------------------------------------------------------------------------------
1 | 'orange',
5 | 'c' => 'grape',
6 | 'b' => 'manggo',
7 | ];
8 |
9 | ksort($fruits);
10 | echo 'Hasil ksort($fruits) :' . json_encode($fruits) . ' ';
11 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_rsort.php:
--------------------------------------------------------------------------------
1 | Hasil rsort($fruits) :' . json_encode($fruits) . '';
7 |
8 | rsort($fruits, SORT_NUMERIC);
9 | echo 'Hasil rsort($fruits, SORT_NUMERIC) :' . json_encode($fruits) . ' ';
10 |
11 | rsort($fruits, SORT_STRING);
12 | echo 'Hasil rsort($fruits, SORT_STRING) :' . json_encode($fruits) . ' ';
13 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_sizeof_1.php:
--------------------------------------------------------------------------------
1 | ' . print_r($creators, true) . '';
6 |
7 | echo 'Jumlah element : ';
8 | echo '' . sizeof($creators) . ' ';
9 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_sizeof_2.php:
--------------------------------------------------------------------------------
1 | 'taylor otwell',
6 | 'products' => ['laravel', 'forge', 'vapor'],
7 | ],
8 | [
9 | 'author' => 'caleb porzio',
10 | 'products' => ['alphine.js', 'laravel livewire'],
11 | ],
12 | ];
13 |
14 | echo '' . print_r($tools, true) . ' ';
15 |
16 | echo 'sizeof($tools) : ' . sizeof($tools) . ' ';
17 | echo 'sizeof($tools, false) : ' . sizeof($tools, false) . ' ';
18 | echo 'sizeof($tools, 0) : ' . sizeof($tools, 0) . ' ';
19 | echo 'sizeof($tools, true) : ' . sizeof($tools, true) . ' ';
20 | echo 'sizeof($tools, 1) : ' . sizeof($tools, 1) . ' ';
21 |
--------------------------------------------------------------------------------
/basics/7_array_mendalam/4_manipulasi_array_sort.php:
--------------------------------------------------------------------------------
1 | Hasil sort($fruits) :' . json_encode($fruits) . '';
7 |
8 | sort($fruits, SORT_NUMERIC);
9 | echo 'Hasil sort($fruits, SORT_NUMERIC) :' . json_encode($fruits) . ' ';
10 |
11 | sort($fruits, SORT_STRING);
12 | echo 'Hasil sort($fruits, SORT_STRING) :' . json_encode($fruits) . ' ';
13 |
--------------------------------------------------------------------------------
/basics/8_fungsi_dasar/1_Basic_Function.php:
--------------------------------------------------------------------------------
1 | 1. Pengenalan Function Dasar";
4 | //============================================1.Teknik Dasar============================================
5 | function hello()
6 | {
7 | echo "Hello World";
8 | }
9 | //Sintaks Call Function
10 | hello();
11 | //============================================
12 |
--------------------------------------------------------------------------------
/basics/8_fungsi_dasar/2_Parameter_Return.php:
--------------------------------------------------------------------------------
1 | 2. Function Dengan Return dan Parameter ";
4 | echo "A.Function dengan return ";
5 | //============================================1.Function dengan return============================================
6 | function HaloDunia()
7 | {
8 | return "Hello World";
9 | }
10 |
11 | //Sintaks Call Function
12 | echo HaloDunia();
13 | //============================================
14 | echo "B.Function dengan parameter ";
15 | //============================================2.Function dengan parameter============================================
16 | //Selain Menyimpan Berbagai Code dalam sebuah Function, Function dapat juga dilakukan sebagai pengembalian nilai
17 | //dimana ini berfungsi untuk menampilkan hasil apa saja yang sudah dikerjakan oleh si Function,
18 | //Lalu akan return sebuah nilai dari sebagai output nya
19 | //Function dengan return akan Dapat Dilakukan dengan 2 cara, yaitu:
20 | function Perkenalan(string $name)
21 | {
22 | echo "Hello, Namaku $name, salam kenal";
23 | }
24 | //Sintaks Call Function
25 | Perkenalan("Haikal");
26 | //============================================
27 |
28 | echo "3. Function dengan return dan parameter ";
29 | //============================================3. Function dengan return dan parameter============================================
30 | function Perkenalan2(string $name)
31 | {
32 | return "Hello, Namaku $name, salam kenal";
33 | }
34 | //Sintaks Call Function
35 | echo Perkenalan2("Haikal");
36 | //============================================
37 |
--------------------------------------------------------------------------------
/basics/8_fungsi_dasar/3_Scope_Variabel.php:
--------------------------------------------------------------------------------
1 | 3. Scope Variabel ";
4 | echo "Contoh 1 ";
5 | //============================================1.Contoh 1============================================
6 | //Deklarasi Variabel global
7 | $a = 1;
8 | echo " 1.Deklarasi Variabel global a = 1";
9 | function fun()
10 | {
11 | echo " 2. Membuat Function";
12 | echo " 3. Menampilkan variabel a didalam function";
13 | echo " $a";
14 | echo " 4. Terjadi error, ketika nampilin a";
15 | echo "kenapa bisa error?? hal ini terjadi error pada PHP karena variabel didalam function dianggap sebagai variabel asing yg belum dideklarasi";
16 | echo " dalam php, global variabel dengan variabel dalam function dianggap sebuah variabel berbeda";
17 | echo " hal ini solusinya yaitu memberi key global lalu diikuti nama variabel, seperti contoh nomor 2 agar variabel tersebut bisa di assign ke variabel global";
18 | }
19 |
20 | fun();
21 | echo $a;
22 | echo "NOTE : dalam php, global variabel dengan variabel dalam function dianggap sebuah variabel berbeda Hanya Ada 2 pilihan, yaitu memberi global variabel atau membuat variabel dengan nama berbeda";
23 | //============================================2.Contoh 2============================================
24 | //Deklarasi Variabel global
25 | echo "Contoh 2 ";
26 | $x = 1;
27 | $y = 2;
28 | echo " 1.Deklarasi Variabel global x = 1, y=2";
29 | function Sum()
30 | {
31 | echo " 2. Membuat Function";
32 | global $x, $y;
33 | echo " 3. Assign global function";
34 | $y = $x + $y;
35 | echo " 4.x = x + y";
36 | echo " 5. Nampilin y = $y";
37 | }
38 |
39 | Sum();
40 |
--------------------------------------------------------------------------------
/basics/8_fungsi_dasar/4_Static_Variable.php:
--------------------------------------------------------------------------------
1 | 4. Static Variabel ";
4 | echo "NOTE : Static berfungsi untuk menetapkan nilai variabel ketika fungsi dipanggil secara terus-menerus";
5 | echo "Contoh 1, Jika Menggunakan Static ";
6 | function add1()
7 | {
8 | static $number = 0;
9 | $number++;
10 | return $number;
11 | }
12 |
13 | echo add1();
14 | echo " ";
15 | echo add1();
16 | echo " ";
17 | echo add1();
18 |
19 | echo "Contoh 2, Jika Tidak Menggunakan Static ";
20 | function add2()
21 | {
22 | $number = 0;
23 | $number++;
24 | return $number;
25 | }
26 | echo add2();
27 | echo " ";
28 | echo add2();
29 | echo " ";
30 | echo add2();
31 |
--------------------------------------------------------------------------------
/basics/8_fungsi_dasar/5_Closure_Function.php:
--------------------------------------------------------------------------------
1 | 5. Closure Function ";
4 | echo "NOTE : Closure Function sebuah teknik menyimpan fungsi didalam sebuah variabel, dan return nya akan ditampung didalam variabel";
5 | echo "Contoh 1 ";
6 | echo "Teknik Dasar ";
7 | $fungsi = function ($a, $b) {
8 | return $a + $b;
9 | };
10 |
11 | var_dump(
12 | $fungsi(1, 2) //true
13 | );
14 |
15 | //======================================================
16 | echo "Contoh 2 ";
17 | echo "Nested Closure Function ";
18 | $fungsi1 = function ($a) {
19 | return function ($b) {
20 | global $a;
21 | return $a + $b;
22 | };
23 | };
24 | //======================================================
25 | //Pemanggilan Nested Closure Function
26 | $fungsi2 = $fungsi1(4);
27 | $result = $fungsi2(3);
28 | //=====================================================
29 | var_dump(
30 | $result //true
31 | );
32 | echo " $result";
33 | //====================================================
34 |
--------------------------------------------------------------------------------
/basics/8_fungsi_dasar/6_Rekursif_Function.php:
--------------------------------------------------------------------------------
1 | 6. Function Rekursif ";
4 | //============================================Function Rekursif============================================
5 | echo "NOTE : Sebuah Function yang melakukan pemanggilan function didalam function dirinya nya sendiri, tanpa melakukan perulangan Contoh ";
6 | function rekursif(int $angka)
7 | {
8 | if ($angka <= 10) {
9 | echo " $angka";
10 | rekursif($angka + 1);
11 | }
12 | return $angka;
13 | }
14 | //Sintaks Call Function
15 | rekursif(1);
16 | //============================================
17 |
--------------------------------------------------------------------------------
/basics/9_form_handling/1_submit_button.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Tombol Kirim - Penanganan Formulir
9 |
10 |
11 |
12 |
13 |
14 |
17 |
18 |
19 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/basics/9_form_handling/3_select.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Input Select - Penanganan Formulir
9 |
10 |
11 |
12 |
13 | Input Select
14 |
15 |
16 | Berikut contoh penaganan formulir dengan input type select
(pilihan)
17 |
18 |
19 | Contoh 1
20 |
21 |
30 |
31 |
32 |
38 |
39 |
40 | Contoh 2
41 |
42 | Tanpa menggunakan attribut value
43 |
44 |
45 |
54 |
55 |
56 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/basics/9_form_handling/4_datetime.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Date Time - Penanganan Formulir
9 |
10 |
11 |
12 |
13 | Date Time
14 |
15 |
16 | Berikut contoh penaganan formulir dengan input type datetime
(tanggal dan waktu)
17 |
18 |
19 | Contoh
20 |
21 |
27 |
28 |
29 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/basics/9_form_handling/5_checkbox.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Check Box - Penanganan Formulir
9 |
10 |
11 |
12 |
13 | Check Box
14 |
15 |
16 | Berikut contoh penaganan formulir dengan input type Check Box
17 |
18 |
19 | Contoh
20 |
21 |
28 |
29 |
30 | ";
35 |
36 | for ($i = 0; $i < count($hobi); $i++) {
37 | echo $hobi[$i] . " ";
38 | }
39 |
40 | echo "sebagai hari spesial saya";
41 | }
42 | ?>
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/basics/9_form_handling/6_radio.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Radio Button - Penanganan Formulir
9 |
10 |
11 |
12 |
13 | Radio Button
14 |
15 |
16 | Berikut contoh penaganan formulir dengan input type Radio Button
17 |
18 |
19 | Contoh
20 |
21 |
30 |
31 |
32 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/basics/9_form_handling/7_file.php:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | File - Penanganan Formulir
20 |
21 |
22 |
23 |
24 | File
25 |
26 |
27 | Berikut contoh penaganan formulir dengan input type File
28 |
29 |
30 | Contoh
31 |
32 |
37 |
38 |
39 | ";
51 | $uploadOk = 1;
52 | } else {
53 | echo "File Bukan Gambar";
54 | $uploadOk = 0;
55 | }
56 | // Cek Apakah Upload Ok 0 atau bukan
57 | if ($uploadOk == 0) {
58 | echo "Maaf, file anda gagal di upload";
59 | // Upload file kalau semua aman
60 | } else {
61 | // Memindahkan file yang diupload ke folder storage
62 | if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
63 | echo "File " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " sudah di upload";
64 | } else {
65 | echo "Upload Error";
66 | }
67 | }
68 | }
69 | ?>
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/basics/9_form_handling/8_multiple_file.php:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | Multiple File - Penanganan Formulir
20 |
21 |
22 |
23 |
24 | Multiple File
25 |
26 |
27 | Berikut contoh penaganan formulir dengan input type Multiple File
28 |
29 |
30 | Contoh
31 |
32 |
37 |
38 |
39 | {$namaBaru} berhasil. ";
55 | } else {
56 | echo "Upload file {$namaFile} gagal ";
57 | }
58 | }
59 | }
60 | ?>
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/basics/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Basic Learning
4 |
5 |
6 | ## Daftar isi
7 |
8 | [1. Hello World](https://github.com/bellshade/PHP/tree/main/basics/1_hello_world)
9 |
10 | [2. Variabel dan Tipe data](https://github.com/bellshade/PHP/tree/main/basics/2_variable_datatype)
11 |
12 | [3. Operator](https://github.com/bellshade/PHP/tree/main/basics/3_operator)
13 |
14 | [4. Pengkondisian](https://github.com/bellshade/PHP/tree/main/basics/4_conditional_statements)
15 |
16 | [5. Perulangan](https://github.com/bellshade/PHP/tree/main/basics/5_perulangan)
17 |
18 | [6. Manipulasi String](https://github.com/bellshade/PHP/tree/main/basics/6_manipulasi_string)
19 |
20 | [7. Array Mendalam](https://github.com/bellshade/PHP/tree/main/basics/7_array_mendalam)
21 |
22 | [8. Fungsi Dasar](https://github.com/bellshade/PHP/tree/main/basics/8_fungsi_dasar)
23 |
24 | [9. Form Handling](https://github.com/bellshade/PHP/tree/main/basics/9_form_handling)
25 |
26 | `10. File Handling - On Progress`
27 |
28 | `11. Cookie & Session - On Progress`
29 |
30 | [12. Database Dasar Prosedural](https://github.com/bellshade/PHP/tree/main/basics/12_database_dasar_prosedural)
31 |
32 | `13. Database Relasional Prosedural - On Progress`
33 |
34 | `14. OOP Dasar - On Progress`
35 |
36 | `15. OOP Lanjutan - On Progress`
37 |
38 | `16. Database Dasar (PDO) - On Progress`
39 |
--------------------------------------------------------------------------------
/basics/backup/loop/recursive_loop.php:
--------------------------------------------------------------------------------
1 | 0) {
23 | echo $num;
24 | // function loop() akan memanggil dirinya sendiri dengan pengurangan value parameternya
25 | loop($num - 1);
26 | }
27 | return;
28 | }
29 |
30 | /**
31 | * Perlu dicatat bahwa untuk pengulangan rekursif ini selain kodenya berbeda dengan for, while, foreach
32 | * juga berbeda dalam penggunaan memorinya.
33 | * Jika for, while, dan foreach untuk setiap pengulangan akan membuat 1 buah tumpukan pada memori
34 | * lalu dijalankan,
35 | * pengulangan secara rekursif akan terus menambah tumpukan sampai sejumlah yang diinputkan
36 | * baru tumpukan fungsi tsb. dijalankan.
37 | */
38 |
39 | // Contoh 1
40 | loop(10);
41 |
42 | // Contoh 2
43 | // loop(100);
44 |
45 | // Contoh 3
46 | // loop(100000);
47 |
48 | /**
49 | * Contoh dengan pengulangan for biasa
50 | * bandingkan dengan contoh ke 3 di atas!
51 | */
52 |
53 | // for (let index = 0; index < 100000; index++) {
54 | // console.log(index);
55 | // }
56 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bellshade/php",
3 | "description": "Referensi materi dasar dan implementasi algoritma untuk developer PHP",
4 | "type": "project",
5 | "license": "MIT",
6 | "require-dev": {
7 | "squizlabs/php_codesniffer": "^3.6",
8 | "phpunit/phpunit": "^9.5",
9 | "overtrue/phplint": "^4.1"
10 | },
11 | "scripts": {
12 | "phpcs": "phpcs . -s --colors --standard=phpcs.xml",
13 | "phpcbf": "phpcbf . --standard=phpcs.xml",
14 | "phpunit": "phpunit tests/",
15 | "phplint": "phplint . --exclude=vendor --no-cache"
16 | },
17 | "require": {
18 | "erusev/parsedown": "^1.7",
19 | "vlucas/phpdotenv": "^5.3"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/config.php:
--------------------------------------------------------------------------------
1 | safeLoad();
9 | $base_url = rtrim(($_ENV['BASE_URL'] ?? 'http://localhost/php'), '/') . '/';
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "devDependencies": {
3 | "markdownlint-cli": "^0.33.0"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | PSR12, tapi tanpa check lineEnding untuk kenyamanan antar platform (CRLF Issue).
4 | */tests/*
5 | */vendor/*
6 | *.js
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | 0
20 |
21 |
22 | 0
23 |
24 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/router.php:
--------------------------------------------------------------------------------
1 | 0;
7 | // die;
8 | if (substr_count(basename($_SERVER["REQUEST_URI"]), '.php') != '') {
9 | return false;
10 | }
11 | require __DIR__ . '/index.php';
12 | }
13 |
--------------------------------------------------------------------------------
/tests/BackTracking/PathFindingTest.php:
--------------------------------------------------------------------------------
1 | setMap([
14 | [0, 0, 1, 0],
15 | [0, 1, 0, 1],
16 | [0, 0, 0, 1],
17 | [1, 1, 0, 0],
18 | ])->pathFind(0, 0);
19 | $expectedPath = [
20 | [1, 2, 0, 0],
21 | [1, 0, 0, 0],
22 | [1, 1, 1, 0],
23 | [0, 0, 1, 1],
24 | ];
25 | $this->assertEquals($expectedPath, $pathFinding->getMapVisited());
26 | }
27 | }
--------------------------------------------------------------------------------
/tests/Searching/BinarySearchTest.php:
--------------------------------------------------------------------------------
1 | getHasil();
17 |
18 | $this->assertEquals($expected, $output, 'Pengujian Algoritma Binary Search');
19 | }
20 | }
--------------------------------------------------------------------------------
/tests/Searching/JumpSearchTest.php:
--------------------------------------------------------------------------------
1 | getHasil();
17 |
18 | $this->assertEquals($expected, $output, 'Pengujian Algoritma JumpSearch');
19 | }
20 | }
--------------------------------------------------------------------------------
/tests/Searching/LinearSearchTest.php:
--------------------------------------------------------------------------------
1 | cari($input, $key);
16 |
17 | $this->assertEquals($expected, $output);
18 | }
19 | }
--------------------------------------------------------------------------------
/tests/Sorting/BubbleSortTest.php:
--------------------------------------------------------------------------------
1 | bubbleSort($input);
14 |
15 | $this->assertEquals($expected, $output);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/Sorting/CountingSortTest.php:
--------------------------------------------------------------------------------
1 | setMaxValue(9)->sort();
15 | $this->assertEquals($expected, $actual);
16 | }
17 | }
--------------------------------------------------------------------------------
/tests/Sorting/PopSort.php:
--------------------------------------------------------------------------------
1 | start();
14 |
15 | $this->assertEquals($expected, $output);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/Sorting/SelectionSortTest.php:
--------------------------------------------------------------------------------
1 | selectionSort($input, $len);
15 |
16 | $this->assertEquals($expected, $output);
17 | }
18 | }
--------------------------------------------------------------------------------
/utilities/Kalkulator_sederhana/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/Kalkulator_sederhana/README.md
--------------------------------------------------------------------------------
/utilities/Kalkulator_sederhana/kalkulator_syzkii/README.md:
--------------------------------------------------------------------------------
1 | ## Kode kalkulator sederhana PHP
2 |
3 | ```php
4 |
5 |
6 |
18 |
19 |
20 |
54 |
55 |
56 |
57 | ```
58 |
59 | Untuk penggunaan cukup mudah, kalian bisa menginputkan Nilai 1 dan Nilai 2.
60 | Misal kalian ingin menjumlahkan, Masukkan saja Nilai 1 = 2 dan Nilai 2 = 2. Maka hasilnya adalah 4.
61 | Dan (kurang, kali, bagi) mengikuti apa yang kalian inputkan
62 |
63 | Seperti ini :
64 |
65 | 
66 |
--------------------------------------------------------------------------------
/utilities/Kalkulator_sederhana/kalkulator_syzkii/kalkulator.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/Kalkulator_sederhana/kalkulator_syzkii/kalkulator.PNG
--------------------------------------------------------------------------------
/utilities/Kalkulator_sederhana/kalkulator_syzkii/kalkulator_index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 |
51 |
52 |
--------------------------------------------------------------------------------
/utilities/Login_Dan_Logout/README.md:
--------------------------------------------------------------------------------
1 | # Login Dan Logout
2 |
--------------------------------------------------------------------------------
/utilities/Login_Dan_Logout/login_dan_logout/README.md:
--------------------------------------------------------------------------------
1 | Menggunakan PHP Versi 5
2 |
3 | ```PHP
4 | login_form_index.php
5 |
6 |
7 |
8 | Login FORM
9 |
10 |
11 |
31 | ```
32 |
33 | Setelah Memasukkan Username dan Password, akan dicek benar tidaknya Username & Password yang kita masukkan seperti dibawah ini :
34 |
35 | ```PHP
36 | login_cek.php
37 |
38 |
60 | ```
61 |
62 | Selanjutnya buat file logout.php sebagai berikut:
63 |
64 | ```PHP
65 | logout.php
66 |
67 | Anda telah logout!";
71 | echo " ";
72 | ```
73 |
74 | Inti dari file ini adalah skrip session_destroy() yang akan menghapus data session **username** dan **password** yang dibuat pada file login_cek.php.
75 |
--------------------------------------------------------------------------------
/utilities/Login_Dan_Logout/login_dan_logout/login_cek.php:
--------------------------------------------------------------------------------
1 |
2 | error_reporting(0);
3 | session_start();
4 | $username=$_POST["username"];
5 | //username adalah name yang digunakan untuk penamaan pada text field Username
6 | $password=$_POST["password"];
7 | //password adalah name yang digunakan untuk penamaan pada text field Password
8 |
9 | if($username=="aku" && $password=="uka")
10 | //jika username yang dimasukkan adalah "aku" dan password "uka". Maka berhasil mendapat hak akses
11 | {
12 | $_SESSION["hak_akses"]="admin";
13 | //Jika Username & Password yang dimasukkan benar, maka akan menuju view_index.php
14 | // CONTOHNYA :
15 | header("location: view_index.php");
16 | }
17 | else
18 | {
19 | header("location: login_form_index.php?pesan=Gagal! DATA TIDAK DITEMUKAN.");
20 | //jika Username & Password yang dimasukkan salah, maka akan kembali ke login_form_index.php sampai Username & Password yang dimasukkan benar
21 | }
22 | ?>
--------------------------------------------------------------------------------
/utilities/Login_Dan_Logout/login_dan_logout/login_form_index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 | Login FORM
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/utilities/Login_Dan_Logout/login_dan_logout/logout.php:
--------------------------------------------------------------------------------
1 | Anda telah logout!";
6 | echo " ";
7 |
--------------------------------------------------------------------------------
/utilities/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Utilities
4 |
5 |
6 | ## Index
7 |
8 | ### D
9 |
10 | - [datetime](https://github.com/bellshade/PHP/tree/main/utilities/datetime)
11 |
12 | ### F
13 |
14 | - [fpdf](https://github.com/bellshade/PHP/tree/main/utilities/fpdf)
15 |
16 | ### K
17 |
18 | - [kalkulator sederhana](https://github.com/bellshade/PHP/tree/main/utilities/Kalkulator_sederhana)
19 |
20 | ### L
21 |
22 | - [login static](https://github.com/bellshade/PHP/tree/main/utilities/Login_static)
23 | - [login & logout](https://github.com/bellshade/PHP/tree/main/utilities/Login_Dan_Logout)
24 |
25 | ### R
26 |
27 | - [recaptcha](https://github.com/bellshade/PHP/tree/main/utilities/reCAPTCHA)
28 |
29 | ### S
30 |
31 | - [simple unit test](https://github.com/bellshade/PHP/tree/main/utilities/SImple_UnitTest)
32 | - [simple CURL](https://github.com/bellshade/PHP/tree/main/utilities/simple_curl)
33 |
--------------------------------------------------------------------------------
/utilities/SImple_UnitTest/README.md:
--------------------------------------------------------------------------------
1 | # PHPUnit Installation
2 |
3 | ## Install PHPUnit
4 |
5 | - Installation
6 | Download the PHPUnit package from the official website [PHPUnit](https://phpunit.de/)
7 |
8 | > Customize PHPUnit version
9 |
10 | - Install PHPUnit
11 |
12 | ```bash
13 | composer require phpunit/phpunit
14 | ```
15 |
16 | - Creating Example Class `WordCount.php`
17 | - Making Test `SimpleTest.php`
18 | - Run Test
19 |
20 | ```bash
21 | ./vendor/bin/phpunit --bootstrap vendor/autoload.php SimpleTest.php
22 | ```
23 |
--------------------------------------------------------------------------------
/utilities/SImple_UnitTest/SimpleTest.php:
--------------------------------------------------------------------------------
1 | countWords($TestSentence);
15 |
16 |
17 | $this->assertEquals(1, $WordCount);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/utilities/SImple_UnitTest/WordCount.php:
--------------------------------------------------------------------------------
1 | AddPage();
15 | $pdf->Cell('Hello World!');
16 | $pdf->Output();
17 | ```
18 |
--------------------------------------------------------------------------------
/utilities/mpdf/README.md:
--------------------------------------------------------------------------------
1 | # mpdf
2 |
3 | > mpdf website [https://mpdf.github.io/](https://mpdf.github.io/)
4 |
5 | - Install v7+
6 |
7 | ```sh
8 | composer require mpdf/mpdf --ignore-platform-reqs
9 | ```
10 |
11 | - examples
12 | > mpdf.php
13 |
14 | ```php
15 | WriteHTML('Hello World! ');
21 | $mpdf->Output();
22 | ```
23 |
24 | - output
25 |
26 |
27 |
--------------------------------------------------------------------------------
/utilities/mpdf/mpdf.php:
--------------------------------------------------------------------------------
1 | WriteHTML('Hello World! ');
9 | $mpdf->Output();
10 |
--------------------------------------------------------------------------------
/utilities/random_password/generate.php:
--------------------------------------------------------------------------------
1 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | Membuat Password Random
32 |
33 |
34 |
35 | Password Random:
36 | = generate_password(10) ?>
37 | Refresh halaman ini untuk membuat password acak lain
38 |
39 |
40 |
--------------------------------------------------------------------------------
/utilities/random_password/readme.md:
--------------------------------------------------------------------------------
1 | # Fungsi Untuk Membuat Password Acak
2 |
3 | Kode untuk membuat password acak/random dengan panjang yang bisa kita tentukan sendiri:
4 |
5 | ```php
6 | function generate_password($length = 8)
7 | {
8 | $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !@#$%^&*()_-=+;:,.?{}[]/|\\-";
9 | $password = substr(str_shuffle($chars), 0, $length);
10 | return $password;
11 | }
12 | ```
13 |
14 | Untuk penggunaannya sangat mudah, cukup panggil fungsi `generate_password()` dan masukkan parameternya sebagai panjang password yang diinginkan, jika tidak dimasukkan apapun maka panjang defaultnya adalah 8.
15 |
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/README.md:
--------------------------------------------------------------------------------
1 | ## Google reCaptcha
2 |
3 |
4 | reCAPTCHA adalah sebuah sistem CAPTCHA yang dapat membedakan antara akses manusia dan otomatis di situs-situs web. Versi aslinya meminta para pengguna untuk membaca teks atau mencocokkan gambar. Versi 2 juga meminta pengguna untuk mengetik teks atau mencocokkan gambar-gambar.
5 |
6 |
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/README.md:
--------------------------------------------------------------------------------
1 | ## Cara Membuat Captcha dengan Menggunakan Google reCAPTCHA
2 |
3 | - step 1
4 | - setting google rechptcha
5 | - Buka link ini : [https://www.google.com/recaptcha](https://www.google.com/recaptcha)
6 | - step 2
7 | - Untuk Label bisa Anda isikan bebas sesuai nama aplikasi yang Anda buat. Untuk kali ini kita beri label `Bellshade`. Kemudian untuk tipe reCAPTCHA nya kita pilih yang reCAPTCHA v2.
8 | - step 3
9 | - Implementsi dengan PHP
10 | - Buat file chaptcha.php
11 |
12 | ```php
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Membuat Google reCAPTCHA
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ```
35 |
36 | - source code juga saya lengkapi dengan gambar di direktori images dari step 1 sampai step 3.
37 | - sekian terimakasih.
38 |
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/captcha.php:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | Membuat Google reCAPTCHA
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/images/0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/reCAPTCHA/google_reCAPTCHA/images/0.png
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/images/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/reCAPTCHA/google_reCAPTCHA/images/1.png
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/images/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/reCAPTCHA/google_reCAPTCHA/images/2.png
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/images/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/reCAPTCHA/google_reCAPTCHA/images/3.png
--------------------------------------------------------------------------------
/utilities/reCAPTCHA/google_reCAPTCHA/images/4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bellshade/PHP/b26cca121d51472c560449382e46ef88e17ba7dd/utilities/reCAPTCHA/google_reCAPTCHA/images/4.png
--------------------------------------------------------------------------------
/utilities/simple_curl/README.md:
--------------------------------------------------------------------------------
1 | # curl api user github
2 |
3 | * api github
4 |
5 | ```bash
6 | https://api.github.com/users/{username}
7 | ```
8 |
9 | * api github prayogaea
10 |
11 | ```bash
12 | https://api.github.com/users/prayogaea
13 | ```
14 |
--------------------------------------------------------------------------------
/utilities/simple_curl/curl.php:
--------------------------------------------------------------------------------
1 | ";
19 | print_r($data_user);
20 | echo "";
21 |
--------------------------------------------------------------------------------
/utilities/simple_curl/prayogaea.php:
--------------------------------------------------------------------------------
1 | ";
19 | // print_r($data_user);
20 | // echo "";
21 | ?>
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | curl | = $data_user['login']; ?>
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | Name
39 | :
40 | = $data_user['name']; ?>
41 |
42 |
43 | Username
44 | :
45 | = $data_user['login']; ?>
46 |
47 |
48 | Link Github
49 | :
50 | = $data_user['html_url']; ?>
51 |
52 |
53 | Organizations
54 | :
55 | = $data_user['company']; ?>
56 |
57 |
58 | Location
59 | :
60 | = $data_user['location']; ?>
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------