惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
WordPress大学
WordPress大学
B
Blog RSS Feed
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
博客园 - Franky
C
Check Point Blog
P
Proofpoint News Feed
H
Help Net Security
月光博客
月光博客
博客园_首页
Stack Overflow Blog
Stack Overflow Blog
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
U
Unit 42
美团技术团队
I
InfoQ
A
About on SuperTechFans

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
PHP #2: Apa itu Variable?
Ryunze · 2026-05-06 · via DEV Community

Ryunze

Gampangnya, Variable adalah tempat kita menyimpan nilai yang nantinya bisa dipakai kembali.

Misal kita ingin menampilkan data Nama Lengkap dari Siswa. Bisa saja langsung tampilkan seperti ini:

<?php
    echo "Budi Sucipto";
?>

Enter fullscreen mode Exit fullscreen mode

Hasil yang akan tampil adalah:

Budi Sucipto

Enter fullscreen mode Exit fullscreen mode

Tapi bayangkan jika Nama Lengkap tersebut dipakai lagi 10x di tempat yang berbeda. Mungkin kamu akan berpikir untuk "Copy Paste" dengan fitur pencarian dari code editor bukan?

Itu baru 10x, gimana kalau nanti lebih? Pusing.. dan itu baru 1 contoh kasus saja, masih ada kasus yang lain dengan masalah yang sama yaitu menggunakan kembali sebuah nilai.


Contoh lain yang lebih nyata, kita ingin menyiram tanaman di halaman rumah. Ada danau kecil di samping rumah. Cukup dengan gayung untuk ambil air dari danau tadi dan langsung siram ke tanaman.

Ukuran gayung normal kita tau segede apa, cukup untuk 1 pot tanaman.

Bagaimana jika ada 10 pot tanaman? Ya, bolak balik danau 10x. Ribet? ga juga, tapi lumayan membuang waktu bagi sebagian orang.

Solusinya, kita bawa 1 ember yang nantinya bisa nampung air kurang lebih setara dengan 10 gayung air.

Otomatis tenaga yang keluar akan lebih sedikit, cukup 1x ke danau dan bisa siram 10 pot tanaman atau bahkan lebih.

Kurang lebih begitu gunanya Variable di pemrograman.


→ Membuat Variable di PHP

Di PHP, tanda $ (dolar) digunakan sebagai penanda utama sebuah variable.

Contoh kita buat variable untuk menyimpan Nama Lengkap.

<?php
    $namaLengkap = "Budi Sucipto";
?>

Enter fullscreen mode Exit fullscreen mode

$namaLengkap : nama variable
= : assign (mengisi)
"Budi Sucipto" : nilai berupa teks]

Kalo dibaca kurang lebih begini:

"Tolong buat sebuah variable ($) dengan nama namaLengkap kemudian isi (tanda =) dengan sebuah nilai berupa teks "Budi Sucipto"

Bisa juga anggapnya begini:

$namaLengkap itu isinya "Budi Sucipto"


Jadi, dari yang tadi kode kita seperti ini-

<?php
    echo "Budi Sucipto";
?>

Enter fullscreen mode Exit fullscreen mode

yang berarti kita minta PHP untuk nampilin teks, sekarang jadinya-

<?php
    $namaLengkap = "Budi Sucipto";
    echo $namaLengkap;
?>

Enter fullscreen mode Exit fullscreen mode

yang berarti kita minta PHP untuk menampilkan isi dari sebuah variable.


Di postingan selanjutnya, kita akan coba lihat sedikit aturan pembuatan variable, baik dari cara penulisan dan nilai apa saja yang boleh disimpan.