$modules = glob( 'modules*', GLOB_ONLYDIR );
$modules_folder = array_shift( $modules );
$products = json_decode( '[{"value":"1000 рублей"},{"value":"500 рублей"},{"value":"5000 рублей"}]', true );
// или
$products = [ [ 'value' => '1000 рублей' ], [ 'value' => '500 рублей' ], [ 'value' => '5000 рублей' ] ];
$total_price = array_reduce( $products, function( $v, $i ) {
$v += intval( $i[ 'value' ], 10 );
return $v;
} );
echo $total_price; // 6500
$mysqli = new mysqli( 'localhost', 'user', 'password', 'database' );
if ( $stmt = $mysqli->prepare( 'INSERT INTO comments( `note`, `name`, `text`, `date` ) VALUES( ?, ?, ?, ? )' ) ) {
$id = 1;
$name = $_POST[ 'namecomment' ];
$text = $_POST[ 'inputcomment' ];
$date = date( 'Y-m-d H:i:s' );
$stmt->bind_param( 'isss', $id, $name, $text, $date );
$stmt->execute();
} else {
echo $mysqli->error . PHP_EOL;
}
$mysqli->close();
$rest_urls = 'https://en.wikipedia.org/w/api.php?action=opensearch&search=test&limit=10&namespace=0&format=xml';
$xml_records = simplexml_load_string( file_get_contents( $rest_urls ) );
foreach ( $xml_records->Section->Item as $item ) {
echo 'Text:' . $item->Text . '<br />';
echo 'Url:' . $item->Url . '<br />';
echo 'Description:' . $item->Description . '<br />';
}