Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
1) Clear sql file from unnecessary lines and leave only
insert
query For example:
INSERT INTO `topwords` (`id`, `word`, `frequency`, `deleted`) VALUES
(1, 'the', 22038615, 0),
(2, 'be', 12545825, 0)
...
2) Add SQL file in a public folder or App/someFolderForSQLFiles 3) Use this in seeder
  $path = base_path('public\topwords.sql');
        $sql = file_get_contents($path);
        DB::unprepared($sql);
Or this:
 $path = 'app/someFolderForSQLFiles/topwords.sql';
 DB::unprepared(file_get_contents($path));
by Luka Tatarishvili
4 years ago
2
Laravel
Seeders
1
Return the current time as a Unix timestamp, then format it to a date:
<?php
$t=time();
echo($t . "<br>");
echo(date("Y-m-d",$t));
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Date
PHP official doc
2
Check whether a variable is an object or not:
<?php
function get_cars($obj) {
  if (!is_object($obj)) {
    return false;
  }
return $obj->cars;
}

$obj = new stdClass();
$obj->cars = array("Volvo", "BMW", "Audi");

var_dump(get_cars(null));
echo "<br>";
var_dump(get_cars($obj));
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Variable Handling
PHP official doc
1
Return an array containing the keys:
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5","Toyota"=>"Highlander");
print_r(array_keys($a));
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Array
PHP official doc
1
Check if the key "Volvo" exists in an array:
<?php
$a=array("Volvo"=>"XC90","BMW"=>"X5");
if (array_key_exists("Volvo",$a))
  {
  echo "Key exists!";
  }
else
  {
  echo "Key does not exist!";
  }
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Array
PHP official doc
1
is_string()
<?php
$values = array(false, true, null, 'abc', '23', 23, '23.5', 23.5, '', ' ', '0', 0);
foreach ($values as $value) {
    echo "is_string(";
    var_export($value);
    echo ") = ";
    echo var_dump(is_string($value));
}
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Variable Handling
PHP official doc
2
Use a regular expression to do a case-insensitive search for "w3schools" in a string:
<?php
$str = "Visit W3Schools";
$pattern = "/w3schools/i";
echo preg_match($pattern, $str);
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
RegEx
PHP official doc
2
Find the position of the first occurrence of "php" inside the string:
<?php
echo strpos("I love php, I love php too!","php");
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
String
PHP official doc
1
Search for the value "Glenn" in an array and output some text:
<?php
$people = array("Peter", "Joe", "Glenn", "Cleveland");

if (in_array("Glenn", $people))
  {
  echo "Match found";
  }
else
  {
  echo "Match not found";
  }
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Array
PHP official doc
0
Check that variable is an array
<?php
$yes = array('this', 'is', 'an array');

echo is_array($yes) ? 'Array' : 'not an Array';
echo "\n";

$no = 'this is a string';

echo is_array($no) ? 'Array' : 'not an Array';
?>
by გიორგი ბაკაშვილი
4 years ago
0
PHP
Array
PHP official doc
0
Results: 1578