xxxxxxxxxx
// Converting int to string
$intValue = 42;
$stringValue = (string) $intValue;
echo $stringValue; // Output: "42"
echo gettype($stringValue); // Output: "string"
// Converting float to string
$floatValue = 3.14;
$stringValue = (string) $floatValue;
echo $stringValue; // Output: "3.14"
echo gettype($stringValue); // Output: "string"
// Converting boolean to string
$boolValue = true;
$stringValue = (string) $boolValue;
echo $stringValue; // Output: "1" (true maps to "1" as a string)
echo gettype($stringValue); // Output: "string"
// Converting an array to string (using implode)
$arrayValue = array('apple', 'banana', 'orange');
$stringValue = implode(', ', $arrayValue);
echo $stringValue; // Output: "apple, banana, orange"
echo gettype($stringValue); // Output: "string"
xxxxxxxxxx
$number = 10;
// To convert this number to a string:
$numberString = (string)$number;
xxxxxxxxxx
$value = 42; // The value you want to convert to a string
// Using strval()
$stringValue = strval($value);
echo $stringValue;
// Using type casting
$stringValue = (string) $value;
echo $stringValue;
xxxxxxxxxx
<?php
class StrValTest
{
public function __toString()
{
return __CLASS__;
}
}
// Prints 'StrValTest'
echo strval(new StrValTest);
?>
xxxxxxxxxx
$teams = array('Equipo 1','Equipo 2','Equipo 3','Equipo 4',"Equipo 5", "Equipo 6");
$results = array();
foreach($teams as $k){
foreach($teams as $j){
if($k == $j){ break; }
$z = array($k,$j);
sort($z);
if(!in_array($z,$results)){
$results[] = $z;
}
}
}
xxxxxxxxxx
def no_of_notes(amt, note):
n = [0, 0, 0]
min_amt = 0
for i in note:
min_amt += i
if amt < min_amt:
i = 0
while amt != 0:
n1 = amt // note[i]
amt = amt - (n1 * note[i])
n[i] += n1
i += 1
else:
n = [1, 1, 1]
if amt == min_amt:
return n
i = 0
amt -= min_amt
while amt != 0:
n1 = amt // note[i]
amt = amt - (n1 * note[i])
n[i] += n1
i += 1
return n
Amount = int(input('Enter a price: '))
note = [500, 200, 100]
result = no_of_notes(Amount, note)
number_of_notes = 0
for i in range(len(note)):
if result[i] != 0:
print(f' Rs.{note[i]} notes = {result[i]}')
number_of_notes += result[i]
print(f'Total number of notes = {number_of_notes}')