Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a substitution between the values of two variables in PHP

Tags:

php

I was wondering if it could be possible to make a substitution between the values of two variables, in PHP.

I can explain it better:

<?php
    $a = "Cat";
    $b = "Dog";

    // The strange/non-existent function I am talking about //
    MakeSubstitution($a, $b);

    // After this (non-existent) function the values of the variables should be:
        // $a = "Dog"
        // $b = "Cat"
?>

So, does it exist? I made searches but I found no results. Thanks in advance.

like image 747
robytur Avatar asked Nov 29 '22 01:11

robytur


1 Answers

Try this :

$a = "Cat";
$b = "Dog";

list($a,$b) = array($b,$a);

echo $a;
echo $b;
like image 85
Prasanth Bendra Avatar answered Dec 06 '22 08:12

Prasanth Bendra