markdown Shorthands和替代语法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Shorthands和替代语法相关的知识,希望对你有一定的参考价值。
## PHP
#### If-else
```php
(condition) ? valuetrue : valuefalse;
```
```php
($isik1['age'] < $isik2['age']) ? -1 : 1; //returns -1 if true, 1 if false
```
#### Switch or While:
```php
switch ($i){ //or while
}
```
```php
switch ($i): //or while
endswitch; //or endwhile
```
#### Accessing array:
```php
$myArr[0]
```
```php
$myArr{0}
```
<br>
## Javascript
#### Accessing element by ID:
```js
elementID
```
<font size="2" color="gainsboro">Example:</font>
```html
<span id='unicorn'>rainbow</span> //changes rainbow to sparkly
```
```js
unicorn.innerHTML = 'sparkly';
```
#### Accessing arrays and objects:
```js
myArr[0]
```
```js
myObj["propertyName"]
```
```js
myObj.propertyName
```
```js
myObj.methodName()
```
#### If-else + function boolean return
```
function myFunction() {
return hours < 24 && minutes < 60 && seconds < 60;
}
```
<font size=2 color=gainsboro>Longer version:</font>
```
function myFunction() {
if (hours < 24 && minutes < 60 && seconds < 60)
return true;
else
return false;
}
```
#### If-else + variable boolean
```
var myVariable = hours < 24 && minutes < 60 && seconds < 60;
```
<font size=2 color=gainsboro>Longer version:</font>
```
var myVariable;
if (hours < 24 && minutes < 60 && seconds < 60)
myVariable = true;
else
myVariable = false;
```
#### Ternary operator (variable example)
```js
if (!maxOptions) {
maxOptions = (type == 'number') ? chosenOptions : (!getOptionRange[2] ? minOptions : countOptions); //all braces can be removed (at the cost readability)
}
```
<font size=2 color=gainsboro>Longer version:</font>
```
if (!maxOptions) {
if (type == 'number') {
maxOptions = chosenOptions;
}
else if (!getOptionRange[2]) {
maxOptions = minOptions;
}
else {
maxOptions = countOptions;
}
}
```
以上是关于markdown Shorthands和替代语法的主要内容,如果未能解决你的问题,请参考以下文章
Markdown 替代品 Asciidoc 介绍
markdown使用语法,typora
Markdown 插入图片
1. 3款免费好用的Markdown笔记应用,可以替代印象笔记
解决:Method definition shorthands are not supported
解决:Method definition shorthands are not supported