Showing posts with label PHP English Version. Show all posts
Showing posts with label PHP English Version. Show all posts

Thursday, February 28, 2019

Sort the array of characters in the array: PHP

If you want to select an array in the array to retrieve data from a particular variable and sorted you can use the following as an example:

<?php

$f = array(
            array('Name' =>'Ucup', 
                  'Class' => 7),
            array('Name' => 'Faizal',
                  'Class' => 9),
            array('Name' => 'Abdul',
                  'Class' => 8)
            );

function sort($r,$d)
{
    return strnatcmp($r['Name'],$d['Name']);
}

usort($f,'sort');
foreach($f as $k=>$v)

    echo $v['Name'];
}

?>

On the listing coding above are arrays in the array contains variables and class name with a certain value, the first array contains the name of the class ucup and 7, both faizal and 9th grade, third grade 8. The name Abdul 

function sequence {return strnatcmp}; // useful to sort the array of characters in the array ($ r $ d); 
foreach ($ f as $ k => $ v); // $ f is the name of an array of data and then split $ k and $ v variable. 
echo $ v [ 'name']; // display the variable ($ v) the contents of the value of 'name'; 

The result:
The contents of the variable names will be ordered


If you have any questions please comment. 
Do not forget to like and share. 
Learn Programming in fajaryusuf.com wrote. :)

Reviewer: FajarYusuf.Com
ItemReviewed: Sort the array of characters in the array: PHP

Creating a pyramid shape: PHP

To create a pyramid we need 3 repetitions for example as follows:


<?php
//PYRAMID TOP
for ($i = 0; $i < 5; $i++) {
 for ($j = 5; $j > $i; $j--) {
 echo '&nbsp';
 }
 for ($k = 0; $k <= $i; $k++) {
 echo '*';
 }
 echo '<br/>';
 }


//PYRAMID BOTOM
 echo "<br/><br/>";

 for ($i = 1; $i <= 5; $i++) {
    for ($j = 6; $j > $i; $j--) {
        echo '*';
    }
     for ($k = 2; $k <= $i; $k++) {
     echo '';
     }
 echo '<br/>';
 }
?>

for ($ i); // repetition i to make the number of rows repetition of 0 to no more than 5, i ++ grow 0-4, echo '<br/>', // to act line 

for ($ j); // repetitions to create a column j j 5 worth no more than i (0), 5-0 j-- reduced, echo '& nbsp' // to display a blank character 

for ($ k); // repetitions k to fill column 0 as i no more and grow, echo '*'; // to produce a character * 


The result:
Creating a pyramid shape: PHP






If you have any questions please comment. 
Do not forget to like and share. 
learn Programming in fajaryusuf.com . :)

Reviewer: FajarYusuf.Com
ItemReviewed: Creating a pyramid shape: PHP

Creating a series of numbers and multiples "dangdingdong": PHP

Here I want to share my experience at that time I was working as a programmer php test and given the matter as follows:

Make a 1-100 number series and each multiple of three figures were changed "ding", each multiple 5 change "dong", and any change multiple 3 & 5 "dingdong".

and here's the answer:


<?php
for($i=1; $i<=100; $i++){

if($i%3==0 && $i%5==0){
echo "dingdong";
}

else if($i%3==0){
echo "ding";
}
else if($i%5==0){
echo "dong";
}

else{
echo $i;
}

}
?>

for ($ i = 1; $ i <= 100; $ i ++); // useful to make a sequence of numbers 1-100 
if ($ i% 3 == 0); // mean if i (1) multiple (%) 3 echo "ding" will feature characters ding // 
if ($ i% 5 == 0); // mean if i (1) multiple (%) 5, echo "dong" will display the character dong // 
if ($ i% 3 == 0 && $ i% 5 == 0); // mean if i (1) multiple (%) 3 & 5, echo "dingdong" dingdong character // will display 

the results:
Creating a series of numbers and multiples "dangdingdong": PHP


If you have any questions please comment. 
Do not forget to like and share. 
Bejar Programming in fajaryusuf.com wrote. :) 

Reviewer: FajarYusuf.Com
ItemReviewed: Creating a series of numbers and multiples "dangdingdong": PHP

Checking Prime Numbers: PHP

To know the number is prime or not using the programming language PHP, we can use the following method:

<?php
$n = 4; // please enter the value of N here
$status = "PRIME";
for ($i = 2; $i <= $n-1; $i++)
{
if ($n % $i == 0) 
{
$status = "NO PRIME";
break;
}
}
echo "Number ".$n." is : ".$status;
?>

$ n = 4; // here you are free to determine what the value or number you want to check, here I am trying to check the status of number 4. if prime prime prime not otherwise status. 

the result:

Checking Prime Numbers: PHP



 4 is not a prime number 



 is now $n I change into 2 

results:
Checking Prime Numbers: PHP
2 is a prime number


If you have any questions please comment. 
Do not forget to like and share. 
Learn Programming in fajaryusuf.com wrote. :) 

Reviewer: FajarYusuf.Com
ItemReviewed: Checking Prime Numbers: PHP

PHP: Introduction Operator

Table of arithmetic operators


Sample Script aritmatika.php

<? php 
$ value1 = 32; 
$ value2 = 8; 
$ number = $ value1 + $ value2; 
$ less = $ nilai1- $ value2; 
$ time = $ value1 * $ value2; 
$ to = $ value1 / $ value2; 
$ remainder = $ value1% $ value2; 
print "Reviews Arithmetic operation Example"; 
print "The value \ $ value1 = $ value1 and \ $ value2 = $ nilai2 <br>"; 
print "\ $ value1 + \ $ value2 = $ amount most"; 
print "\ $ value1 - \ $ value2 = $ less than most"; 
print "\ $ value1 * \ $ value2 = $ times the most"; 
print "\ $ value1 / \ $ value2 = $ for most"; 
print "\ $ value1% \ $ value2 = $ leftovers most"; 
?>

The result:

Know the assigment operator

The following table of symbols and Functions of the assignment operator used

Example Scripts assignment.php

<?php
$data1=10;
$data1+=2;

print "Nilai \$data1 adalah $data1 <br><br>";
$data2=10;
$data2-=5;

print "Nilai \$data2 adalah $data2 <br><br>";
$data3=10;
$data3*=4;

print "Nilai \$data3 adalah $data3 <br><br>";
$data4=20;
$data4/=5;

print "Nilai \$data4 adalah $data4 <br><br>";
$data5=12;
$data5%=7;

print "Nilai \$data5 adalah $data5";
?>

The result:



Know Comparison Operators

Table of comparison operators such as below
Example Scripts perbandingan.php

<?php
$a=12;
$b=13;

print "Variabel \$a = $a dan \$b = $b <br><br>";

print("Nilai \$a == \$b adalah %s <br>",$a==$b);
print("Nilai \$a <> \$b adalah %d <br>",$a<>$b);
print("Nilai \$a > \$b adalah %d <br>",$a>$b);
print("Nilai \$a < \$b adalah %d <br>",$a<$b);
print("Nilai \$a <= \$b adalah %d <br>",$a<=$b);
print("Nilai \$a >= \$b adalah %d <br><br>",$a>=$b);

print"Keterangan:<br>";
print "Nilai 1 berarti Benar/True<br>";
print "Nilai 0 berarti Salah/False";

?>

There are other operators are included in the category of comparison operators are ternary operator " ?". The use of the ternary operator is identical to the user if .. else . Pnggunaan example of the ternary operator is as follows:

Example Scripts ternary.php
























The result:


Know the String Operator

There are two types of operators used string operators . (Dot) operator . = (Colon equals) operator concatenate the arguments sent word to say that the right in an argument. While the operator . =Concatenate the arguments with a right hand to the left. The second function is similar operator to concatenate the words before and after. But the use of the operator. = More practical and operational results can be saved to the same variable. For more details, you can try the following script program. script String.php



<?php
$a="Selamat ";
$b=$a."Datang";
print "$b <br>";
$a="Selamat"; $b.="";print "$b<br>";
?>


The result:








If you have any questions please comment. 

Reviewer: FajarYusuf.Com
ItemReviewed: PHP: Introduction Operator

PHP: Data Types and Variables

PHP: Data Types and Variables
Variable is a very important thing in a programming language. Since most of the programming process is to process the data stored in the variable.

variable name

There are some rules that need to be considered in making a variable in PHP is:
  1. Each variable is always preceded by a $ (dollar)
  2. Allowed three types of characters are letters, numbers and underscores
  3. The first character must be a letter or underscore
  4. If a variable name is two, there should be no spaces in between.
  5. Small and large letters will be different ( case sensitive )

Giving value to the variable

To assign a value to a variable, you can follow the formula as follows:
$variable_name = value of the data;
example:

<?php
$value1=12; //type data integer
$value2=8.99; //type data float atau double
$value3="Tes Nilai variabel string"; //type data string
print "Tipe data integer : $value1<br>";
print "Tipe data double : $value2<br>";
print "Tipe data string : $value3";
?>

The result:
PHP: Data Types and Variables


Single and Double Quote

To display the data type string, we can use single or double quotes. To display double quotation marks itself way is as follows. Try the following data scripts.
<? php 
print "Bandung is known as \" the Flower City \ "";?>


Permanent

Together with a variable constant but its value is fixed or permanent. By providing a constant value on the data type, we will not be able to vary the value. If we use data that are long and hard to remember constants should be used. The formula used is as follows:
define("constant_name","constant_value");
An example of its use is as a script the following courses:

<?php
define("phi",3.14);
define("Hasilnya","Keliling Lingkaran");
$jarijari=7;
$keliling=2*phi*$jarijari;
printf("Jari-jari lingkaran adalah $jarijari<br>");
printf("Nilai phi=%s<br>",phi);
printf("%s=$keliling",Hasilnya);
?>

the result:
PHP: Data Types and Variables


Constants from another file

To call a constant value in other files You can use the following ways:
require("namafile.php"); or includ("namafile.php");
Example: 

constant.php
<?php
define("phi",3.14);
define("Hasilnya","Keliling Lingkaran");
define("GantiBaris","<br>");
define("Selesai","thanks");
$jarijari=7;
$luas=phi*$jarijari*$jarijari
?>
constant1.php
<?php
require("konstanta.php");
print"Jari-jari = $jarijari".GantiBaris;
print"Nilai phi".phi.GantiBaris;
print"Luas=$luas".GantiBaris;
print Selesai;
?>

The result:
PHP: Data Types and Variables


See Variable Data Types

There are some functions provided by PHP to detect the data type of a variable, such as:

  • is_string (variable_name) , ascertain whether the data type of a variable is string
  • is_int (variable_name) , to ascertain whether a variable is an integer data type
  • is_numerical (variable_name) , ensure is variable data type is a numerical / figures
  • is_double (variable_name) , ascertain whether the variable data type is a double
  • is_array (variable_name) , ascertain whether the data type of the variable is an array
  • is_bool (variable_name) , ascertain whether the data type is a boolean variable
Function GetType (variable_name) ; used to determine the variable data used

<? php 
$ number = 78; 
$ font = "Learning PHP fast"; 
$ number = 22.78; 
print "The variable \ $ count"; 
if (is_int ($ number)) 

    print "True, integers most"; 

Else 

    print "Wrong, not integers most"; 

Print "most"; 
print "Are variable \ $ letters of type string? Reviews"; 
if (is_string ($ letter)) 

    print "True, most string-type"; 

Else 

    print "Wrong, not the type string"; 

Print "most"; 
print "Are variable \ $ number of type boolean? <


print "True, this variable of type boolean most"; 

Else { 
    print "Wrong, but not of type boolean type" .gettype ($ number); 

?>

The result:
PHP: Data Types and Variables


See Values ​​and Data Types Variables

To determine the value and data type of a variable, you can use the following functions:

<?php
$angka=98;
$huruf="Fajaryusuf.com";
$bilangan=34.7;

echo "Variabel \$angka adalah ";
echo var_dump($angka)."<br>";
echo "Variabel \$huruf adalah ";
echo var_dump($huruf)."<br>";
echo "Variabel \$bilangan adalah ";
echo var_dump($bilangan)."<br>";
?>

The result:
PHP: Data Types and Variables




Next, you can learn  Introduction to PHP Operator.

Reviewer: FajarYusuf.Com
ItemReviewed: PHP: Data Types and Variables

TENTANG SITUS

SITUS INI ADALAH SITUS INFO GAME TERBARU DAN JUGA SITUS PEMBELAJARAN PEMROGRAMAN DAN JUGA PEMAHAMAN TERHADAP TEKNOLOGI KOMPUTER. KALIAN BISA MENGIKUTI PEMBELAJARAN PEMROGRAMAN DENGAN BERTAHAP PADA MATERI YANG SUDAH SAYA SEDIAKAN, JIKA ADA MATERI YANG MEMBINGUNGKAN SILAKAN LAKUKAN KOMENTAR PADA MATERI YANG ANDA TANYAKAN ATAU KALIAN BISA MENGHUBUNGI SAYA DIHALAMAN KONTAK.